The cake, popular at birthdays, had been at the centre of a long-running dispute between the retail giants.
M&S accused Aldi of copying the design of its product when it made the Cuthbert the Caterpillar chocolate cake.
Both companies confirmed an agreement has been reached but could not release details due to confidentiality clauses.
Last April M&S launched the lawsuit against its rival in a bid to force it to pull its cake from shelves and agree to not sell anything resembling it in the future.
The following month, Aldi started selling its caterpillar cake again, after making a series of changes to the 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 allowed the legal claim to be withdrawn and said the retailers had struck a “confidential agreement” in November.
Aldi said Cuthbert was now “free” following the dispute and “looking forward to seeing all his fans again very soon”.
A spokesman for M&S said the firm is “very pleased with the outcome” of its claim, which it said was to “protect the IP (intellectual property) in our Colin the Caterpillar cake”.
The two supermarkets are embroiled in a separate copyright battle over allegations Aldi imitated an M&S “light-up” gin liqueur product.
“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,” the spokesman for M&S said.
“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.”