The European Court of Justice ruled the definition of feta was reserved for cheese from Greece alone as it had been registered as a protected designation of origin by the European Commission in 2002.
The ruling was a victory for Greece, where feta is believed to have been produced from a blend of sheep and goat milk for around 6,000 years.
Denmark and Germany had wanted to use the name for feta-like cheese made in their countries.
Greek Agriculture Minister Evangelos Bassiakos welcomed the ruling as the end of the legal battle.
There is no right of appeal against Tuesday's decision.
The decision was also welcomed by Greek dairy producers who said the ruling would help market feta against rival products.
Explaining its decision, the court recalled a Commission opinion that special breeds of sheep and goats and the fauna in Greece gave Greek feta a specific aroma and flavour.
It also said feta in other EU states was often associated with Greece and its culture and was marketed with labels showing its Greek heritage.
But the decision drew criticism from the Danish Dairy Board which said it undermined legal rights in Europe.
The Greek government has campaigned in the EU court for over a decade for geographical protection of local feta.
Germany and Denmark had asked the European court to annul the decision by the Commission in 2002 to make feta a Greek-only product - the same kind of protection as that given to Italy's parma ham and French champagne.
The Commission welcomed the court ruling and said it would set an important precedent for the EU's system of protecting the names of certain food products which are regionally made.
But Hans Bender, director of the Danish Dairy Board's office in Brussels, criticised the ruling.