The New York City Council voted on Thursday to banish horse-drawn carriages from Central Park in two years, setting the stage for the elimination of an attraction as old as the park itself.

The Council vote on the bill imposing the ban was a definitive, if not final, step toward ending a politically contentious debate over the future of the carriage industry, which some people criticize as a form of animal cruelty with no place in a crowded park and others embrace as a vestige of old-world charm.

Mayor Zohran Mamdani’s office helped craft the bill, which passed 40 to 7, a veto-proof margin.

“The mayor will sign this bill, and the Mamdani administration is working every day to ensure we can do so while providing the strongest possible protections for the owners and workers in this industry,” said Sneha Choudhary, a spokeswoman for Mr. Mamdani.

The legislation dictates that horse carriages will not be allowed to operate in the city as of June 2028, but it includes few concrete details about how the city will address the economic fallout of eliminating the industry for the roughly 200 owners, drivers and stablehands whose livelihoods are tied to it. The bill is also vague on what will become of the 180 carriage horses.

Officials say that the nearly two years between the bill’s passage and the ban’s effective date give them enough time to hash out those details. Opponents of the ban, including the union that represents the owners, are not reassured.

In a letter sent to city officials on Wednesday, lawyers for the union, Transport Workers Union Local 100, vowed to challenge the legislation in court should the council pass it.

The bill’s passage was a major victory for animal-rights activists, who have waged a yearslong campaign against the carriages. Those efforts, which had previously failed to attract substantial political support, gained momentum this summer with the death of Romanch Mahajan, an 18-year-old tourist from India.

Mr. Mahajan was in a carriage with his family when the driver stepped out to take their picture. The horse bolted, and the teenager’s mother fell from the carriage. In trying to help her, he fell as well and hit his head on the ground.

Since his death, his family has been vocal in pushing for a carriage ban, including with an emotional appeal to Council members via videoconference from their home in India. On Thursday, several family members were in City Council chambers for the vote banning the industry. They have also taken steps to file a wrongful-death lawsuit against the city and Con Edison, saying that stray voltage caused the horse to become agitated.

By last week, Julie Menin, the Council speaker, and Mr. Mamdani had agreed on the legislation.

Gaurav Mahajan, Romanch Mahajan’s uncle, fought back tears on Thursday, describing the Council vote as “incredibly bittersweet.” It will not bring his nephew back, he said, but it will “ensure no other family goes through what we are experiencing.”

The union argues that not only are the horses well cared for and heavily regulated, but that the bill’s provisions for addressing the economic fallout, which include creating a “horse-drawn-cab-industry transition plan” by next April, amount to empty promises.

John Samuelsen, the T.W.U.’s international president, said on Wednesday that the bill did “not have any protections in it” for workers. The industry employs roughly 150 drivers, a couple of dozen stable hands and farriers who shoe horses, according to the union.

“We’re not going to give up,” one of those drivers, Onur Altintas, a 41-year-old father from New Jersey, said after the vote. He owns one carriage medallion, which drivers need to operate and for which he said he had paid more than $300,000, and four horses: Shadow, Trigger, Gix and Starlight. He described the city’s carriage horses as cared-for “domestic animals” who would “all go to the slaughterhouse” if the industry was abolished.

Mr. Samuelsen reiterated his belief that Ms. Menin was using a “contrived public safety crisis” to cater to real estate interests eager to develop Manhattan parcels now occupied by horse stables. Ms. Menin has denied that accusation.

Mr. Samuelsen and other critics have repeatedly noted that Mr. Mahajan’s death, while tragic, was the first known death of a carriage passenger in Central Park in the industry’s history.

Those critics include President Trump, a New York native who lamented the Council’s move in a social media post on Thursday.

“The Horse-drawn Carriage in New York City is a quintessential New York experience,” Mr. Trump wrote. “So sad that, for political reasons, we will see it go!”

Those who oppose the ban have also said that speeding cyclists, including those on e-bikes and pedicabs, pose far greater hazards. Since Mr. Mahajan’s death in June, a cyclist died trying to avoid colliding with an unleashed dog, and a pedestrian was killed after being hit by a cyclist.

Jim Gennaro, a councilman and self-described equestrian, has argued that provisions for the care of the horses to be retired are inadequate and that finding appropriate homes for them will not be easy. He estimated the cost of caring for a horse at $25,000 a year.

“Sometimes it takes months to find suitable lifelong accommodation for even one 26-year-old retired horse,” Mr. Gennaro, a Queens Democrat, said in a statement on Wednesday evening.

In their letter to city officials on Wednesday, the union’s lawyers said they had ample grounds for a legal challenge, including the absence of any provision in the bill to compensate those who had spent “many thousands of dollars” to buy carriage medallions from the city.

The 68 medallions have cost owners as much as $400,000 a piece, according to the union. Should the bill pass, the lawyers wrote, the union would seek a court order blocking it “before the ink dries.”

Nicholas Paolucci, a spokesman for the city’s Law Department, said officials were “reviewing the letter.”

“We are confident the legislation is grounded in the law and will be prepared to defend it,” he added.

Ms. Menin said on Wednesday that setting the ban’s effective date two years from now gave city officials enough time to help drivers and others employed in the industry to find new jobs and that she was committed to working with the Mamdani administration to achieve that goal.

A spokeswoman for the mayor said the administration “has been working on a detailed plan for the transition of the work force and industry, and we have begun discussion of compensation for medallion owners.”

But Mr. Altintas scoffed.

“They’re going to find a new job for the 60-years-old person?” he asked. “It doesn’t make sense, because that person they invested their past and future for that business. That person cannot do that. You know what they’re going to do? They’re going to suicide.”