The D.C. Council voted unanimously Tuesday to impose some of the tightest limits in the nation on Airbnb and other short-term rental companies.

If signed by Mayor Muriel E. Bowser (D), the measure would prevent D.C. property owners from renting out second homes on a short-term basis and bar them from renting spare rooms or basements in their primary residences for more than 90 days per year when the host is away.

Bowser has said she thinks the bill is too restrictive but has not threatened to veto it — partly because it passed with enough votes to override a veto.

Airbnb swiftly denounced the council’s action.

“The D.C. Council’s reckless vote today is the latest example of the misleading tactics used to pass fiscally irresponsible home sharing policy,” Airbnb spokeswoman Crystal Davis said in a statement. “This Council managed to accomplish the seemingly impossible today, simultaneously depriving D.C. residents of $64 million in supplemental income annually and then sending D.C. taxpayers a bill for $104 million.”

Davis said Airbnb would “remain committed to ensuring home sharing is protected in our nation’s capital,” but did not specify what actions the company may take. The company had previously warned it might take its case directly to voters with a 2020 ballot initiative.

On Tuesday, Airbnb also filed a lawsuit against the city of Boston over a law that contained some provisions similar to D.C.’s legislation.

Supporters of the crackdown said it was necessary in a city where short-term rentals are making an overheated real estate market even more difficult for would-be home buyers and renters.

“District residents looking to purchase a home will no longer be competing with investors who seek to list them on lucrative short-term rental platforms,” D.C. Council member Kenyan R. McDuffie (D-Ward 5), who authored the bill, said in a statement after the vote.

The bill passed after a flurry of last-minute debate among lawmakers over whether it was too strict. Council members proposed amendments that would have softened some of the legislation’s tougher provisions.

Only one of those changes was adopted: a measure allowing homeowners to apply for an exemption from the bill’s annual cap on the amount of time a unit can be rented for.

D.C. Council member Charles Allen (D-Ward 6), who introduced the amendment, said it was written to accommodate District residents serving in the military or diplomatic corps, who could be called away for long periods unexpectedly.

The measure passed by the council would take effect Oct. 1, 2019. That would give the city time to create an enforcement and licensing agency and to resolve inconsistencies under which most short-term rentals are technically in violation of zoning regulations.

The bill would affect thousands of D.C. property owners who have turned to home sharing to earn income, as well as the tourists and business travelers who use the service to find lodging in the nation’s capital.

The legislation has been pushed by the hotel industry and its unions, affordable-housing activists and community groups that argue short-term rentals are destroying the character of residential neighborhoods.

Airbnb and similar companies have lobbied hard against the plan, saying it would cost property owners tens of millions of dollars in lost income.

Both sides have run television ads and social-media campaigns to try to sway lawmakers and win public support.

The council unanimously gave preliminary approval to the bill on Oct. 2. On Oct. 16, however, it unexpectedly delayed the final vote because of concerns over an estimate from D.C. Chief Financial Officer Jeffrey S. DeWitt that the legislation would cost the city $104 million over four years.

DeWitt contended that passage of the bill would lead the city government to begin enforcing existing prohibitions on short-term rentals in residential areas, where between 80 and 90 percent of such rentals take place.

The city has very rarely enforced those regulations as short-term rentals have grown in popularity. The District earns tens of millions of dollars a year in taxes on those rentals — despite the fact that they are technically illegal.

In a fiscal impact statement, DeWitt said the measure would cost the city $21.7 million in fiscal 2019, and $104.1 million through fiscal 2022, mostly from lost tax revenue if those short-term rentals are eliminated. But council Chairman Phil Mendelson (D), who championed the bill, said there was no reason to believe the Department of Consumer and Regulatory Affairs would start enforcing zoning regulations that it has largely ignored.

Mendelson recruited the other 12 council members to sign a letter asking the city zoning commission to permit short-term rentals. After receiving the letter, the five-member commission called a special meeting and asked the D.C. Office of Planning to study the issue and recommend the necessary changes.

It wasn’t clear, however, how long it would take the zoning commission to get the recommendations from the planning office and adopt the changes.

The debate over short-term rentals has become part of a broader controversy over gentrification in the District. Critics say Airbnb, HomeAway, VRBO and similar short-term-rental companies are driving up housing costs.

But Airbnb and its allies, including many hosts, argue that people living in the city need the extra income from renting their properties to afford to stay in the District.

Home-sharing companies say the hotel industry and its unionized workers are trying to eliminate competition. About 9,000 short-term rentals operate in the District, competing with about 31,000 hotel rooms.

The rental companies say that short-term rental properties represent such a small fraction of the District’s 300,000 housing units that the overall effect on rents is minimal.

Fenit Nirappil contributed to this report.