Both supermarkets confirmed an agreement has been struck but said they could not release details of the “confidential” deal.
It came after M&S first launched the lawsuit against Aldi in April last year in a bid to force its rival to take its Cuthbert the Caterpillar cake off the shelves and agree to not sell anything resembling it in the future.
Aldi ran a campaign on social media with the hashtag #FreeCuthbert and changed the packaging design to show the caterpillar sweet treat behind bars.
In May, the German discounter started selling its caterpillar cake again after making changes to its chocolate face design.
On Thursday, Deputy Master Timothy John Bowles signed off an agreement in a consent order filed at the High Court.
The order, which was first reported by The Telegraph, allowed the legal claim to be withdrawn and said the retailers had reached a “confidential agreement” in November.
An M&S spokesman said: “The objective of the claim was to protect the IP (intellectual property) in our Colin the Caterpillar cake and we are very pleased with the outcome.”
Meanwhile, Aldi said that Cuthbert was now “free” following the dispute.
An Aldi spokesperson said: “Cuthbert is free and looking forward to seeing all his fans again very soon.”
M&S and Aldi are also involved in a separate copyright dispute over allegations the German rival copied an M&S “light-up” gin liqueur product.
The M&S spokesman added: “Like many other UK businesses, large and small, we know the true value and cost of innovation and the enormous time, passion, creativity, energy and attention to detail, that goes into designing, developing and bringing a product to market and building its brand over many years.
“So it is understandable that we want to defend our intellectual property and protect our suppliers – many of them small businesses that have worked with us for decades.”