"Lindt's sale of bear-shaped chocolates wrapped in a golden foil with a red ribbon is neither a violation of Haribo's 'Gold Bear' trademark nor an illegal imitation of the fruit gum products," the court ruled.
The German candy manufacturer had taken Lindt & Spruengli to court in 2012 after the Swiss chocolatier began selling "Lindt Teddy" figurines in 2011 for the Christmas season.
Haribo claimed that the gold-foil packed Lindt teddies were an imitation of its gold-coloured jelly bear packaging, which also features a bear with a red ribbon around its neck.
The Swiss company argued however that the teddy bear figurines were inspired by its best-selling "Gold Bunny" chocolates, which are also wrapped in a golden foil and decorated with a red ribbon and a little bell.
The bunnies were first produced in 1952, and are bestsellers during the Easter season.
A German court had initially ruled in favour of Haribo but an appeal court threw out that verdict, finding that the chocolate teddies could not be mistaken for Haribo's jelly sweets.
To end the dispute, the case was then brought to the Federal Court of Justice for a final ruling.
For the court, the chocolate teddies bore no resemblance to the much smaller jellies.
'Teddy lovers delight'
The two-centimetre (0.78-inch) tall gummy bear has become the best-known product of Haribo, a company created in 1920 in the western city of Bonn.
First sold in its current form in 1967, about 100 million such bears are now produced daily.
Lindt meanwhile claims on its website that its teddy "sets . . . more than 60 million hearts racing" every year.
In a statement welcoming the favourable court's ruling, the Swiss chocolatier said it "will continue to delight all Lindt chocolate lovers with the Lindt Teddy".
Lindt added that both parties "have agreed to refrain from making any substantive comments on the matter itself".
Lawsuits over product trademarks are often brought in Germany, where the justice system is generally viewed as offering strong protection against violations.
Also on Wednesday, the same court issued a ruling on a dispute brought by Germany's Sparkasse savings banks against Spain's giant Santander over the red colour used on their logos.
The German bank claims it has the exclusive right to that tint in Germany.
But the court ruled that the case needs to be heard again on appeal.
In another similar case, Beiersdorf has been arguing before German courts that the blue colour used on its Nivea cream tin boxes cannot be used by rival Unilever in its products.