Mayor de Blasio’s bumpy bid to shrink the horse-buggy industry was trampled Thursday after the Teamsters union that represents drivers suddenly backed out of a deal with City Hall.

The stunning about-face forced the City Council to cancel a vote slated for Friday that would have cut the number of horses by two-thirds and restricted the popular tourist rides to Central Park.

It was the second failed attempt by the mayor to keep his campaign promise to wealthy donors that he would ban horse carriages from crowded city streets.

“This is a huge loss for the mayor,” said a City Hall source.

“He did a lot of arm-twisting to try and get this done and deliver to one of his top donors, and now all he’s left with is chinks in his armor that show he’s truly vulnerable.

“He’s got to be hurting, even if he claims he’s not.”

A defiant de Blasio vowed to plow on with yet another scheme to rein in the industry, despite increasing calls from weary council members to let the marginal issue drop.

In an unusual scene Thursday morning, the mayor sat in the front passenger seat of his black SUV for 16 minutes after it pulled up to City Hall while 50 carriage workers gathered between his vehicle and the historic building.

The mayor called two aides into the vehicle to powwow before coming out to address the media for less than two minutes — and put the blame for the collapsed deal on the Teamsters.

“We had a good-faith agreement with them that was worked on for many weeks, and they didn’t keep their agreement,” he told a throng of reporters. “It’s as simple as that.”

Teamsters Local 553 had publicly maintained as recently as Tuesday that its members were on board with the measure — even as the carriage drivers they represent said they had not been consulted.

The union changed its tune only after the 1.3 million-member Central Labor Council — concerned about the potential for significant job losses — called for an end to the increasingly unpopular deal.

Pressure also came from reluctant council members and Transport Workers Union Local 100 — which jumped into the fray last week to protect the largely immigrant pedicab drivers, who would have been barred from the southern portion of Central Park ­under the bill.

“It was an outrageous scenario that the powers-that-be would side with the moneyed interests in New York City against an ­immigrant workforce,” TWU ­Local 100 President John Sam­uelsen told The Post.

“This was a manufactured ­crisis. It became evident that this was about something else.”

The mayor invested an enormous amount of political capital in the deal, to make good on a campaign promise to animal-rights advocates and supporters.

Those included former Edison Properties honcho Stephen Nis­lick and recycling exec Wendy Neu — leaders of the animal-rights group NYCLASS — who helped round up least $900,000 for de Blasio’s 2013 mayoral campaign and the progressive nonprofit he now operates.

A NYCLASS spokesman confirmed that Nis­lick and Neu made phone calls, but only to allies on the council, to ensure there were enough votes to pass the legislation.

Opponents included unions, pedicab drivers and the Central Park Conservancy.

Local 553 officials insisted they backed off out of concern for their members’ jobs.

Council officials said the legislation was pulled because of the union’s reversal — not ­because the legislative body lacked the votes to pass it.

But Majority Leader Jimmy Van Bramer (D-Queens) disputed that. “There were a lot of folks who were unsure about this bill and about some of the portions of the bill,” he said.