Treasury minister David Gauke said: “This is a significant victory and should serve as a warning to those tempted by tax avoidance – it simply does not work.”

Jim Harra, director general of business tax at HM Revenue & Customs, said: “This was clear tax avoidance. It was an attempt to manufacture losses to deny the public purse the tax due.”

A spokesman for Stagecoach said: “We believe it is right that we pay our fair share of taxes and we are committed to doing so. The case involved the interpretation of historical and technical issues which are no longer relevant under current legislation, and no additional tax is payable by Stagecoach as a result of the ruling.

“These historic[al] transactions involved Stagecoach investment in its subsidiaries, and the first-tier tribunal ruling did not challenge the commercial background behind those transactions.”

The company said it had not ruled out an appeal, and added it would “take time to consider the findings ... before deciding on the way forward”.

Stagecoach, which had sales of £3.2bn last year, employes 34,000 staff in the UK in its extensive bus and rail franchises. It also holds a 49% stake in Virgin Rail Group. It paid £25.7m in tax for 2015 on profits of £165m. The failed tax avoidance scheme, however, related to 2011.

HMRC said there were 11 similar disputes with other companies that would be affected by Monday’s ruling. The total tax at stake from these cases is £179m. Tax inspectors have already secured £485m in tax and interest from 16 other groups which used similar schemes to try to avoid tax.

KPMG had negotiated a “success fee” for its work on Stagecoach’s tax structure. After the scheme was challenged by HMRC, solicitors from KPMG were appointed to act for Stagecoach in the court dispute.

The close involvement of KPMG in the dispute comes despite the accountancy firm publishing a code of conduct on tax advice three years ago. That code said: “We will not advise clients to enter into transactions with the main purpose of securing a tax advantage clearly contrary to the intention of parliament in enacting the relevant legislation.”

It added: “We do not act as mere advocates of tax planning structures or arrangements. We shall only promote transactions or structures that have both substance and business purpose.”

On Monday, KPMG declined to answer questions about the Stagecoach tax scheme. A spokesperson said: “We are unable to comment on specific client situations, particularly where they are the subject of litigation.”

Stagecoach is a stock-market-listed company but its largest shareholders are its founders, Ann Gloag and her brother, Sir Brian Souter, who remains chairman of the business. Together the siblings control 26% of shares.

Souter is a major donor to the Scottish National party. He donated £1m in 2014 before Scotland’s independence referendum.

Nicola Sturgeon, the Scottish first minister, has been among the most outspoken opponents of corporate tax avoidance. A year ago, the SNP leader said “a whole political establishment” had negligently allowed tax avoidance to become routine.

In 2000, Souter helped finance a campaign opposed to the abolition of a controversial law that restricted how sexuality was taught in schools. The law, known as clause 28, banned the “promotion of homosexuality” and the teaching of the “acceptability of homosexuality”. It was repealed in Scotland in June 2000 and in England and Wales in November 2003.