Airbnb and HomeAway settled a lawsuit against San Francisco on Monday by agreeing to help the city ensure that all local hosts are registered. The agreement caps a multiyear struggle by Airbnb’s hometown to rein in burgeoning vacation rentals, which critics say divert precious housing stock into the lucrative travel market.

“The two largest (vacation-rental services) will only include legal listings, and the city has the tools for quick, effective enforcement,” City Attorney Dennis Herrera said at a crowded news conference in City Hall. He was flanked by lawmakers and representatives of groups that say short-term rentals hurt them, including landlords, hotel workers’ unions and tenant advocates. “Enforcement with real teeth will begin in short order after a phase-in period.”

A San Francisco law requiring vacation-rental hosts to register with the city took effect in February 2015. Only about 2,100 out of 8,000 hosts on Airbnb have done so. San Francisco wants properties registered so it can ensure that they meet city rules that aim to prevent illegal hotels in homes, such as requiring vacation-rental hosts to be permanent residents and capping whole-home rentals at 90 days.

Airbnb, later joined by rival HomeAway, sued San Francisco in federal court in June after supervisors unanimously passed legislation holding companies liable for steep fines and criminal penalties if they arrange guest stays at unregistered properties.

MBA BY THE BAY: See how an MBA could change your life with SFGATE's interactive directory of Bay Area programs.

Airbnb and HomeAway said the law violated their rights under the Communications Decency Act, a federal law that largely shields Internet service providers from legal responsibility for the content of postings on their sites, and the First Amendment. But U.S. District Judge James Donato appeared highly skeptical of those arguments at court hearings in the fall. In November, he ordered San Francisco and Airbnb to work together on a system for companies to comply with the law by registering their hosts.

The agreement will allow hosts to comply with San Francisco laws “with simplicity, certainty, visibility,” said Chris Lehane, Airbnb’s head of global public policy, in a conference call with reporters. “We want to move on and talk about other things.”

Those other things probably include preparing for a public offering on Wall Street. Airbnb is among the world’s most-valuable startups, but ongoing regulatory disputes could threaten the $31 billion value investors have placed on it in private fundraising. Lehane took pains in the Monday call to emphasize that Airbnb increasingly is forging agreements with cities worldwide.

City officials, including Mayor Ed Lee, heaped praise on the agreement.

“This is a decisive victory for San Francisco,” said Supervisor Aaron Peskin, describing Airbnb as being dragged “kicking and screaming” to the negotiating table.

“We demanded a system to prevent landlords taking entire units off the market,” said London Breed, Board of Supervisors president. “I’m thrilled the companies have agreed to abide by sensible regulations.”

Likewise, Airbnb hosts said they welcomed “a new era of cooperation” that would allow them to continue earning extra income by renting to travelers.

“The issue of home sharing has been fraught and often used as a political hot potato, with the relationship between City Hall, prominent platforms like Airbnb and HomeAway, hosts and housing advocates often boiling over into unpleasant conflict,” wrote Peter Kwan and Laura Thompson, co-chairs of the Home Sharers Democratic Club, in a Medium post.

The U.S. District Court will oversee implementation of the new system. Airbnb and HomeAway will pay the costs to implement it on their respective websites, and will have eight months to phase it in. Its most basic requirement is that all short-term rentals listed on Airbnb and HomeAway must include a city registration number.

Airbnb and hosts had complained that San Francisco’s registration process, which required an in-person visit to a city office, was too cumbersome. Now, Airbnb and HomeAway will use a pass-through system to send hosts’ registration applications directly to the city, which will verify that the application information is correct. The city can reject hosts who don’t meet its requirements. Hosts must submit supporting documents, such as utility bills and voter registration cards, to prove that they comply with city rules. Hosts must separately apply for a business-registration certificate from the Treasurer’s Office, but that can take place online.

The companies will give the city a monthly list of all San Francisco listings so its Office of Short-Term Rentals can verify that they are actually registered. If the city finds any listings with invalid registrations, the companies will cancel future stays and remove those listings.

Within six months, Airbnb and HomeAway will require all new hosts to be registered with San Francisco before they can post a rental listing on either site. Existing hosts will be registered in three batches; details and timing on that are still being worked out.

Hosts could attempt to duck the law by listing on other sites, such as Craigslist or TripAdvisor’s FlipKey. But those sites will be on the hook for fines of up to $1,000 a day per listing and criminal penalties if they help arrange bookings of unregistered listings, city officials said.

“This will be a powerful deterrent for those tempted to illegally convert the city’s housing stock into mini hotels,” Herrera said in a statement. “For those who have been turning badly needed rent-controlled units into vacation spots, that is coming to an end once and for all.”

Carolyn Said is a San Francisco Chronicle staff writer. Email: csaid@sfchronicle.com

Twitter: @csaid

Past coverage

The San Francisco Chronicle has reported in depth about the extent of Airbnb use in San Francisco, including data that showed how most hosts were flouting city rules on registration.

2016: As city lowers boom, Airbnb and rivals thrive:

http://projects.sfchronicle.com/2016/airbnb

2015: The Airbnb effect: www.sfchronicle.com/airbnb-impact-san-francisco-2015/

2014: Window into Airbnb’s hidden impact on S.F.: www.sfchronicle.com/business/item/Window-into-Airbnb-s-hidden-impact-on-S-F-30110.php