The trustee for the brokerage arm of Lehman Brothers Holdings Inc is entitled to $4 billion in margin assets that have been the subject of a long-running legal fight with Barclays Plc , a bankruptcy judge said on Monday.

As part of the ruling, Barclays will have to return $2 billion in margin collateral to the trustee, which is liquidating what is left of the brokerage business.

U.S. Judge James Peck issued the ruling from the bench at a court hearing on the dispute.

In February, the judge ruled that Lehman's hurried sale of its North American business to Barclays at the height of the financial crisis in September 2008 was fair .

At that time, Peck said Barclays was not entitled to roughly $4 billion in margin collateral that Lehman had posted to cover outstanding derivatives trades. Since then, the parties have had to return to the judge after being unable to agree on how to implement the terms of his decision.

The $2 billion that Barclays must return was the amount of margin collateral in its possession at the time of that February ruling.

The other $2 billion in margin assets is held by third parties or the trustee, according to Barclays.

Today's bench ruling brings finality to this issue by confirming that the $4 billion in Lehman cash and other margin assets belong to the trustee, said William Maguire, a lawyer for the trustee charged with liquidating the Lehman Brothers Inc brokerage arm.

A Barclays spokesman, Michael O'Looney, said after Monday's ruling that the bank plans to appeal portions of the February decision.

After the February ruling, Barclays had argued that it should be able to use Lehman-related derivatives losses it had incurred to offset some of the margin collateral it had to return.

On Monday, Peck rejected this argument and also stated that Barclays would have to pay 5 percent interest, an amount lower than the 9 percent Lehman had requested in court papers.

The February ruling upheld the overall sale and stated which party was entitled to three classes of disputed assets, the largest of which was the $4 billion in margin collateral. In that ruling, Peck said Barclays was entitled to roughly $1.1 billion in clearance box assets, a conclusion that Lehman did not dispute.

(Reporting by Jeff Roberts; Editing by Steve Orlofsky and Tim Dobbyn)