The German government has won its fight to retain its right to veto hostile takeovers of Volkswagen and to have a final say on any possible factory closures.

The ruling by the European Court of Justice means Berlin avoids fines worth tens of millions of euros and leaves the north-west regional state of Lower Saxony, where Volkswagen is headquartered, with the power to block takeovers and other key decisions.

The European Commission, the EU's executive arm, took Germany to the European Court of Justice in 2011 for failing to obey in full a 2007 judgement and repeal all the legislation.

The 1960 law on the privatisation of Volkswagen gave German public authorities special powers over the company, with 20% stakes going to the federal government and Lower Saxony.

Porsche found the VW law a barrier when it sought to take over VW in 2008. Porsche's bid foundered and it was subsequently bought by VW last year.

After the 2007 court ruling, Germany abolished parts of the law, including board seats for public authorities and a 20% voting cap regardless of how much a shareholder actually owned.

The Commission said Berlin had failed to remove the provision which gave Lower Saxony the 20% blocking stake and took Germany back to the ECJ.

The German authorities argued that this provision on its own did not contravene EU rules and the court agreed.

"It brings clarification after long litigation ... and brings the matter to a close; the issue is finished," a spokeswoman said.