In this April 21, 2010 file photo, oil can be seen in the Gulf of Mexico, more than 50 miles southeast of Venice on Louisiana's tip, as a large plume of smoke rises from fires on BP's Deepwater Horizon offshore oil rig. (Gerald Herbert/The Associated Press)

In this April 21, 2010 file photo, oil can be seen in the Gulf of Mexico, more than 50 miles southeast of Venice on Louisiana’s tip, as a large plume of smoke rises from fires on BP’s Deepwater Horizon offshore oil rig. (Gerald Herbert/The Associated Press)

NEW ORLEANS (AP) — BP wanted its money back — hundreds of millions of dollars of it — but a federal judge says the oil giant must stick by an agreement with companies that got payouts after claiming the 2010 Gulf oil spill hurt their business.

BP argued Wednesday that a flawed funding formula in the settlement is giving money to businesses for questionable claims, and they should be forced to return it.

But U.S. District Judge Carl Barbier says a deal is a deal. Barbier had ordered the formula changed several weeks ago

Barbier ruled the payments agreed to by BP included a provision that they would not be changed by later court action.

His ruling thwarts BP’s latest attempt to control its soaring liability from the spill, which may be nearing $50 billion.