Image copyright Getty Images

HM Revenue & Customs has lost its bid to recover up to £50m in stamp duty from the sale of the Chelsea Barracks in 2007.

Three Court of Appeal judges decided that the tax office had pursued the wrong party for the tax.

The purchaser, a firm owned by the Qatar Investment Authority, had used a type of Islamic finance that meant a bank actually owned the property.

HMRC said it was "disappointed" by the ruling.

"The Court of Appeal ruling supports our view that SDLT [stamp duty land tax] is payable. We are disappointed that the decision makes that tax much harder to collect so we are considering an appeal," HMRC said.

The judges' decision is likely to reignite criticism of the complexity of the UK tax system, if HMRC itself can be caught off guard. It will also expose alternative financing arrangements to more scrutiny from tax campaigners.

In the ruling, Lord Justice Lewison said there was "nothing surprising" about which firm HMRC should have pursued for the tax.

Project Blue, the investment vehicle ultimately owned by the Qatari ruling family, claimed that HMRC was now out of time to pursue Masraf al Rayan, a Qatar-based bank.

The result, and how it was arrived at, shows that HMRC needs more resources to do its job, said Richard Murphy, director of Tax Research UK.

"This needs to be a serious kicking for the people involved including the senior management of HMRC," he said. "We cannot run a tax authority on the cheap."

The tax office had won a decision in a tribunal in December 2014 for £38m stamp duty land tax to be paid, based on a £959m purchase price for the site. However, this decision was then taken to the Court of Appeal.

HMRC then sought stamp duty land tax worth £50m against the £1.25bn paid by the bank to Project Blue - a figure that as well as the £959m purchase price included tax and further development costs.

Image copyright Getty Images Image caption The Qatar royal family is a joint owner of the Shard in London

Project Blue had used a type of finance that complied with Islamic law, which forbids lending money for interest. It used an arrangement called Ijara.

"Under an Ijara arrangement a bank or other financial institution buys the asset that the customer wishes to acquire and then leases that asset to him," said Lord Justice Lewison in the judgement.

"The rent is calculated in such a way that the bank will receive a return on its investment. The customer will also have an option to buy the asset. However, it is critical to appreciate that the bank will be the real owner of the asset for the term of the lease, and the customer will not."

Qatar is now a large player when it comes to investments in London. It is a joint owner of the Shard, has a 20% stake in the owner of Heathrow airport and a significant stake in Barclays after helping the bank avoid a government bailout in 2008.

Project Blue said in a statement: "In good faith, Project Blue Ltd paid the full original sum demanded in advance of the First Tier Tribunal hearing in 2013. We welcome the important clarifications provided by the Court of Appeal. Project Blue Ltd has always fully complied with all UK taxation matters and will continue to do so."