The Revenue said it protected £8.7m as an outcome of the decision, with a further £22m protected in related cases using the same scheme.
The scheme, known as Project Sussex, was marketed to Greene King, a major brewery, by EY. It involved a £300m internal loan between Greene King and another member of the same group, Greene King Acquisitions.
The aim was for one company in a group to get tax relief on interest paid to another group company without that other company paying tax on the income it received.
While HMRC initially defeated the scheme in the First-tier tribunal in 2011, the Upper Tribunal upheld the decision three years later.
HMRC argued at the time that the case constituted an “artificial” transaction.
The decision means that HMRC will recover a total of £30m in due taxes from Greene King and others that have used the scheme.
David Milne QC, for HMRC, said in his skeleton argument, “[The] transactions were structured in the curious way they were in order to attempt to take advantage of a perceived loophole in the loan relationships legislation so as to achieve a tax mismatch within the Greene King group.
“If the scheme were to succeed, GKBR [Greene King] would be entitled to a deduction (for corporation tax purposes) of over £21m for interest paid on an intergroup loan, without any company in the group being chargeable on the corresponding receipt.”
Jane Ellison, financial secretary to the Treasury, said, “This is a significant victory. Tax avoidance schemes like these attempt to deprive the exchequer of money that's needed to provide the vital public services and infrastructure we all rely on. We will not let such schemes go unchallenged.”
Jim Harra, HMRC’s director general of business tax, said HMRC is cracking down hard on tax avoidance and will pursue taxpayers who participate in avoidance schemes, both individuals and large corporations.
A Greene King spokesman said, "We accept the Court of Appeal’s decision on this long-running case. Greene King is a British business with a 217-year heritage and a major contributor to the Treasury with over a quarter of our turnover paid to HMRC.
"We are proud of the significant contribution we make to the UK and the Treasury and in the last financial year alone we paid £570m in taxes.
"We always ensure we comply with tax regulations by following the advice of our legal counsel and taxation experts, including in this case, Ernst & Young LLP."
An EY spokesperson declined to comment.