By Valentina Pop and Sam Schechner

Apple Inc. won a major battle with the European Union when the bloc's second-highest court on Wednesday sided with the U.S. company over a EUR13 billion ($14.8 billion) tax bill that EU antitrust officials had said the company owed to Ireland.

The case stems from a 2016 decision by the European Commission, the bloc's top antitrust enforcer, which said that Ireland must recoup EUR13 billion in allegedly unpaid taxes between 2003 and 2014, money the commission said constituted an illegal subsidy under the bloc's strict state-aid rules.

In a stinging rebuke to the commission, the General Court said it annulled the decision because the commission had failed to meet the legal standards in showing that Apple was illegally given special treatment.

Margrethe Vestager, who is in charge of competition at the commission, said she would "carefully study the judgement and reflect on possible next steps" and vowed to continue investigations into national tax deals with corporations to establish whether they constitute illegal subsidies.

"The Commission stands fully behind the objective that all companies should pay their fair share of tax," she said, adding that if one EU government gives corporations tax benefits that aren't available to their rivals, "this harms fair competition in the EU."

The 2016 decision against Apple earned Ms. Vestager the nickname "tax lady" from President Trump. She recently launched two antitrust probes into Apple, is now also responsible for tech regulation and is considering imposing a digital tax on tech giants.

The decision is a blow to Ms. Vestager, who is also currently fighting Google in court over three separate antitrust decisions -- with fines totaling $9.4 billion -- that the commission has levied under her watch against the Alphabet Inc.-owned search giant for allegedly anticompetitive conduct.

In a September hearing at the General Court, Apple's lawyers said the commission's decision to call for the payment "defied reality and common sense" and Apple's CEO Tim Cook at the time slammed the decision as "total political crap."

The company however had parked the sum in an escrow account, pending adjudication in EU courts.

The commission can still challenge the Apple ruling at the bloc's top court, the European Court of Justice. In recent comments, however, Ms. Vestager pointed to the limitations of state-aid law in enforcing what she describes as "paying your fair share of tax."

Overturning the Apple decision, while a loss for the commission, gives ammunition to tech-industry critics -- including Ms. Vestager -- who say current tax and competition laws must be updated to curb alleged abuses by large tech companies. European countries and the U.S. are currently at an impasse in international talks over how and whether to update the global tax system to make tech companies pay more levies where their customers are based.

Several countries, including France, have unilaterally imposed taxes on tech companies. EU leaders, including Ms. Vestager, have said the EU will do the same if there isn't progress at an international level by the end of this year.

Apple and Ireland on Wednesday applauded the annulment of the tax case. Ireland reiterated that it gave no special treatment to Apple, and said that the company had paid taxes according to "normal Irish taxation rules."

Apple said that it supports international talks over how countries should divide up taxation rights for multinational companies. "This case was not about how much tax we pay, but where we are required to pay it. We're proud to be the largest taxpayer in the world as we know the important role tax payments play in society," an Apple spokesperson said.

In a sign that this ruling may dent Ms. Vestager's reputation, some of her former supporters in the European Parliament questioned the level of preparation she put into this case.

"Sometimes, the Commissioner for Competition would be well-advised to restrain her eagerness for catchy political headlines and instead prepare her cases more thoroughly, so that they can hold up in a court of law," said German center-right MEP Markus Ferber who in 2016 backed the commission's decision against Apple. "High-profile decisions like these being overturned is quite the disservice to the cause of tax justice," he said in an email.

Advocates for fairer taxation were less critical of Ms. Vestager. "Today's court decision illustrates how difficult it is to use EU state-aid rules to collect tax," said Tove Maria Ryding with the European Network on Debt and Development, a grouping of nongovernmental organizations active in the field of debt and finance. "If we had a proper corporate tax system, we wouldn't need long court cases to find out whether it is legal for multinational corporations to pay less than 1 per cent in taxes," she said by email.

The tax case overturned in Wednesday's ruling is based on a quirk of EU law aimed at creating a level playing field for companies across the bloc by forbidding governments from granting companies some types of state-aid.

The case was Ms. Vestager's first major taxation case in a series she brought against Amazon.com Inc., Starbucks Corp., Nike Inc., Fiat Chrysler Automobiles NV and Engie SA of France.

So far, the General Court has sided with Starbucks in a taxation case but with the commission in its case against Fiat. Amazon in March had argued at the General Court that Ms. Vestager's 2017 order to pay Luxembourg $277 million in allegedly unpaid taxes was riddled with legal and factual errors.

Commission lawyers refuted those allegations and said that neither Amazon nor Luxembourg was able to prove that they didn't get an unfair advantage from the tax deal.

A central issue in the Apple case was whether two Irish tax rulings granted to Apple in 1991 and 2007 gave a form of special treatment to the company, or whether they just reiterated an interpretation of Irish tax law as it was applied more generally.

Those rulings allowed two Irish-registered Apple units to attribute only a small sliver of some $130 billion in profit to Ireland in an 11-year period. The commission said all that revenue should be attributed to Ireland, but the Irish government and Apple say they split the profit reasonably, given that almost all of Apple's intellectual property is developed in the U.S., not Ireland.

In Wednesday's ruling, the General Court said that, despite the gaps in the contested tax rulings, the commission hadn't proven the Irish government granted a special advantage to Apple that was unavailable to other companies in Ireland.

The commission had argued in its decision that the rulings gave Apple a selective advantage because the iPhone maker and Ireland offered no specific evidence to justify how the profit was allocated. The EU also argued the rulings deviated from the "arm's-length principle," a standard for setting commercial conditions between units of the same company as if they were independent.

Ireland contended however that its tax rulings "did not depart from 'normal' taxation" because it had merely followed a portion of Irish tax code that says nonresident companies shouldn't pay income tax on profit that isn't generated in Ireland.

Write to Valentina Pop at valentina.pop@wsj.com and Sam Schechner at sam.schechner@wsj.com