The European Union's order for Apple to pay €13bn in back taxes to Ireland "defies reality and common sense", the US company has said.

Apple made its comments as it launched a legal challenge against the 2016 ruling.

The iPhone maker also accused the executive European Commission of using its powers to combat state aid "to retrofit changes to national law", in effect trying to change the international tax system and in the process creating legal uncertainty for businesses.

Apple's arguments at the General Court, Europe's second-highest, came after the EU executive in 2016 said the tech giant benefited from illegal state aid due to two Irish tax rulings that artificially reduced its tax burden for over two decades.

The case is key to European Competition Commissioner Margrethe Vestager's crackdown on sweetheart deals for multinationals, a campaign that has also led to action against Starbucks, Fiat, Engie, Amazon and others.

Apple's Chief Financial Officer Luca Maestri led a six-strong delegation to the court where a panel of five judges will hear arguments from both sides, as well as Ireland, Luxembourg, Poland and the EFTA Surveillance Authority, over two days.

"The commission contends that essentially all of Apple's profits from all of its sales outside the Americas must be attributed to two branches in Ireland," Apple's lawyer Daniel Beard told the court.

He said the fact the iPhone, the iPad, the App Store, other Apple products and services and key intellectual property rights were developed in the United States, and not in Ireland, showed the flaws in the commission's case.

"The branches' activities did not involve creating, developing or managing those rights. Based on the facts of this case, the primary line defies reality and common sense," Mr Beard said.

"The activities of these two branches in Ireland simply could not be responsible for generating almost all of Apple's profits outside the Americas."

The Apple tax case appeal: All you need to know

Mr Beard dismissed criticism of the 0.005% tax rate paid by Apple's main Irish unit in 2014, which was cited by the commission in its decision, saying the regulator was just seeking "headlines by quoting tiny numbers".

Paying an average global tax rate of 26%, Apple has said it is the largest taxpayer worldwide and is now paying around €20bn in US taxes on the same profits that the commission said should have been taxed in Ireland.

In its current financial quarter, Apple expects revenue of $61-64bn and a gross margin of 37.5-38.5%.

Ireland is also challenging the commission's decision.

"As Ireland has already emphasised, it undermines legal certainty if state aid measures are used to retrofit changes to national law and legal certainty is a key principle of EU law; one upon which businesses depend," Mr Beard said.

"Some may want to change the international tax system; but that is a tax law issue not state aid," he said.

Ireland said it had been the subject of entirely unjustified criticism and that the Apple tax case was due to a mismatch between the Irish and US tax systems.

"The commission's decision is fundamentally flawed," Paul Gallagher, lawyer for Ireland, told the court.

Apple has fiercely rejected the tax bill, while the US government insists the order by Brussels constitutes a major breach of international tax law.

"The European Commission has tried to rewrite Apple's history in Europe, to ignore Ireland's tax laws and, in doing so, to disrupt the international tax system," Tim Cook said in an open letter in 2016.

The group insists that it is in the US, where the company invests in research and development and thus creates wealth, that it must pay taxes on the revenue in question.

This became possible after a major tax overhaul in the US at the end of 2017 that allowed Apple to repatriate profits made abroad. Apple has promised to pay Washington a tax bill of $37 billion, in addition to the taxes already paid in the US.

That argument is "perfectly irrelevant", the commission's lawyer said. "There is no tax mismatch here," he added.

The two days of hearings are taking place in a tense trade context between the EU and the US.

US President Donald Trump accuses Europeans of deliberately attacking American technology giants.

The EU's competition supremo, Margrethe Vestager, has in particular been accused by Mr Trump of "hating" the US.

He has slammed her as the "tax lady" because of the investigations and heavy fines imposed on US tech firms such as Google.

Pending the conclusion of the case, Apple has blocked the funds in an escrow account - a total of €14.3 billion after interest.

Apple, which has been in Ireland since the 1980s, employs around 6,000 people in Cork.

The first indications of how the Apple case may finish will come as early as 24 September when the same EU court will rule on whether Ms Vestager was right to demand unpaid taxes from Starbucks and a unit of Fiat Chrysler.

Lawyers for the commission will also make their case tomorrow.

The court is expected to rule in the coming months, with the losing party likely to appeal to the EU Court of Justice and a final judgment could take several years.