An attempt by BP to offload a major part of its Gulf of Mexico oil-spill compensation bill on to the US rig operator Transocean has been thrown out by a US court.

The setback comes in the run-up to the main legal case against BP and its partners on 27 February in New Orleans, which will rule over who is to blame for the Deepwater Horizon accident, in which 11 workers died.

Shares in the oil group fell 2.7% after a federal judge upheld a clause in the drilling contract that shielded Transocean from having to pay compensation for livelihoods damaged by the Macondo blowout in 2010.

But the district judge, Carl Barbier, left open the possibility that Transocean might still have to pay punitive damages or civil penalties imposed by the US government under the federal Clean Water Act.

BP put a positive gloss on the court decision. "Today's ruling makes clear that contractors will be held accountable for their actions under the law," said a company spokesman.

"While all official investigations have concluded that Transocean played a causal role in the accident, the contractor has long contended it is fully indemnified by BP for the liabilities resulting from the oil spill. The court rejected this view."

Transocean, whose shares rose 9.3%, claimed victory. "This confirms that BP is responsible for all economic damages caused by the oil that leaked from its Macondo well, and completely discredits BP's ongoing attempts to evade both its contractual and financial obligations," the company said.

And independent analysts, such as those at the UBS investment bank, said the legal decision meant Transocean's potential liability for the Deepwater Horizon explosion was "materially diminished", whereas the position of BP remained uncertain.

BP has already paid out $7bn (£4.5bn) in claims to third parties who have suffered losses and has an outstanding provision of $8.2bn for further claims and litigation, suggesting third-party claims are expected to top $15bn.

However, plaintiffs lawyers say compensatory claims could end up totalling more than the $20bn that BP has set aside in its Gulf coast restoration fund.

Two US government investigations have put most of the blame for the disaster on BP, suggesting that the oil group, which replaced its chief executive over the accident, is likely to face the largest share of any fines levied. There has been mounting speculation that BP may come to some kind of agreement with the US justice department ahead of the 27 February court hearing but Morgan Stanley said the cost of this deal could be in the region of $25bn for the oil group.