Apple has been told it will not have to pay Ireland €13bn (£11.6bn) in back taxes after winning an appeal at the European Union's second highest court.
It follows a record ruling by the European Commission against the US tech giant in 2016.The EU's General Court said it had annulled that decision because the Commission had not proven Apple had broken competition rules.
It is a blow for the EU which wants to crack down on alleged tax avoidance.
However, it has the right to appeal the decision to Europe's highest court, the European Court of Justice.
"This case was not about how much tax we pay, but where we are required to pay it," Apple said in a statement. "We're proud to be the largest taxpayer in the world as we know the important role tax payments play in society."
The Irish government - which had also appealed against the ruling - said it had "always been clear" Apple received no special treatment.
"The correct amount of Irish tax was charged... in line with normal Irish taxation rules."EU Competition Commissioner Margrethe Vestager, who brought the case, said she would "study the judgment and reflect on possible next steps".
The European Commission brought the action after claiming Ireland had allowed Apple to attribute nearly all its EU earnings to an Irish head office that existed only on paper, thereby avoiding paying tax on EU revenues,
The commission said this constituted illegal aid given to Apple by the Irish state.
However, the Irish government argued that Apple should not have to repay the taxes, deeming that its loss was worth it to make the country an attractive home for large companies.
Ireland - which has one of the lowest corporate tax rates in the EU - is Apple's base for Europe, the Middle East and Africa.
In Wednesday's ruling, the Luxembourg-based General Court sided with that position, saying there was not enough evidence to show Apple was given preferential treatment.
The ruling could spell bad news for EU efforts to crack down on other cases of alleged corporate tax avoidance.
Margrethe Vestager has spent much of her time in office campaigning against tax schemes she argued were anti-competitive. However, last year she lost a case against Starbucks which was accused of owing €30m in back taxes to the Netherlands.
Rulings over Ikea and Nike's tax arrangements in that country are also due soon.
Jason Collins, partner and head of tax at law firm Pinsent Masons, said: "Apple's victory shows that European courts are unwilling to call beneficial tax regimes state aid, even when designed to attract foreign investment - provided they apply the rules consistently.
"This will be a very welcome outcome for other multi-nationals who have been watching this case closely."
However, he said Brussels was likely to appeal and EU efforts to tackle tax avoidance would continue.
"We expect the EU to continue applying pressure in this area," he said.