Embattled New York City taxi mogul Gene Freidman has avoided jail time after settling with a bankruptcy court-appointed trustee ordered to seize 46 of his cabs.

Lawyers for Freidman and Chapter 7 trustee Gregory Messer announced the settlement during a Tuesday hearing held at the U.S. Bankruptcy Court in Brooklyn that was supposed to decide whether Freidman should be held in contempt for allegedly violating agreed-upon terms of surrender for the taxis.

Judge Carla E. Craig had previously threatened to jail Freidman if he defied the order.

Freidman only turned in 23 of the 46 vehicles before a Jan. 10 deadline, squabbling with Messer's lawyers the whole way. He has since surrendered 39 cabs. Messer's lawyers said in court Tuesday that upon further investigation, three of the cabs covered by the order didn't actually belong to the holding companies Freidman put into bankruptcy protection in July 2015. Those cases are being administered jointly under Hypnotic Taxi LLC.

As for the remaining four vehicles, Freidman has agreed to pay Messer $35,000 in lieu of surrender. The 39 cabs will be operated by a third party taxi management company and sold off piecemeal to pay back Freidman's creditors.

"We hope to have the vehicles operational in the next week or so," Messer counsel Gary F. Herbst of LaMonica Herbst & Maniscalo LLP said in court. "What we've heard is that they're in pretty decent shape."

Still at issue is the $92,000 missed payment on the medallions that prompted the trustee to seize the cabs from Freidman in the first place, plus an alleged additional $60,000 in taxes and surcharges owed to the city's Taxi & Limousine Commission. Freidman and the trustee will spend the next two weeks negotiating on that front, Herbst said.

"If we can't resolve [those issues], we will be back before the court," he added.

Freidman owns 830 taxi medallions, more than any individual in New York City. It's no coincidence that his taxi empire has crumbled just as ridesharing startups like Uber and Lyft have broken the city's yellow cab monopoly.

He lost control of the Hypnotic Taxi Chapter 11 cases in September after he failed to produce a reasonable reorganization plan and then attempted to surrender the 46 taxis outside the Queens office of Citibank in a publicity stunt.

That month, Freidman was evicted from his Manhattan office space after falling behind more than $170,000 on rent. In July, he was ordered by New York state Attorney General Eric Schneiderman to pay $250,000 in penalties for not keeping accurate receipts and paying his drivers late on their credit card fares.