A Mission District property that was at the center of a fight over neighborhood gentrification will become the site of 100 percent affordable housing now that the city has agreed to buy the parcel for about $18.5 million.

The Mayor’s Office of Housing and Community Development is in contract to buy 1515 South Van Ness Ave., a former electrical contracting warehouse that had been on track to be replaced by market-rate apartments. Instead, the property will now accommodate about 150 housing units affordable to low-income families.

Mayor London Breed said the deal would help “families who are at risk of displacement.”

“For too long we have not built enough housing, especially affordable housing, and we are working to change that with investments like this one,” said Breed. She said the Mission neighborhood would continue to be a priority for her administration. The city was to announce the deal Tuesday.

Along with the so-called “Beast on Bryant” and “Monster in the Mission,” 1515 South Van Ness Ave. — detractors called it the “the Mess on South Van Ness” — was targeted by activists who argued that upward pressure from market-rate development leads to displacement of low-income residents and the businesses that serve them.

Eventually developer Lennar Multifamily was able to win political support by agreeing to make 25 percent of the units affordable, creating discounted space for artists and makers and contributing $1 million to a cultural district formed to preserve the neighborhood’s Latino heritage and community.

But the concessions, combined with rising construction costs, eventually made the project so costly that it no longer made sense for the developer, according to market sources. Instead of breaking ground, Lennar decided to sell.

San Francisco construction costs are up more than 50 percent since 2015, and recently edged out New York City as the highest in the country. A unit of affordable housing costs between $600,000 and $800,000 to build, depending on building type and materials.

Supervisor Hillary Ronen, who represents the Mission District, said she was disappointed that Lennar decided not to go forward with the complex, but pleased with the outcome.

“After Lennar pulled out, the best thing that could happen was a 100 percent affordable project on that site,” Ronen said.

With construction unlikely to start before 2021 or 2022, Ronen said she hopes the space can be used for community arts on an interim basis. It recently served as a homeless Navigation Center for about nine months.

The project is the eighth affordable housing site that San Francisco has acquired over the past four years in the Mission District, which consistently has had one of the city’s highest eviction rates. Combined, the projects will bring more than 1,000 affordable units to the neighborhood. Projects already under construction include 157 units at 1950 Mission and 143 units at 1990 Folsom St.

“We want to keep the momentum going in the Mission,” said Kate Hartley, director of the Mayor’s Office of Housing and Community Development.

The 1515 South Van Ness acquisition is being made possible, in part, by a $5 million transit-oriented housing grant from the Metropolitan Transportation Commission, Hartley said. The site is a few blocks from the 24th Street BART Station and major bus lines on Mission Street.

The project will likely require about $45 million in city funds. The money would come from the housing bond, most likely to be for $600 million, slated for the November ballot. If the bond passes, the project would start in about three years. If it doesn’t pass, it may take longer.

“With the housing bond we could move this forward really fast,” Hartley said.

Todd David, executive director of the Housing Action Coalition, said the city’s acquisition of the site for affordable housing is “a phenomenal outcome.” But he said he is concerned that market-rate housing projects like the initial 1515 South Van Ness proposal are becoming increasingly infeasible, both because of construction costs and the fees and requirements the city imposes.

“Just because we have a good outcome doesn’t mean the process was a good process,” David said. “We were lucky that the stars aligned and the mayor came in and saved the day. The higher probability was that we were going to end up with no housing at all on that site.”

Hartley said that the city has been looking at possible acquisitions of several market-rate projects that have “gone dormant because of construction costs.”

Mission District market projects that have been approved and then put on the market before construction started include a 75-unit development at a former laundromat at 2918 Mission St., and a 117-unit complex at 2675 Folsom St. from which developer Axis Development abruptly walked away after winning approvals in 2018.

Hartley said she didn’t know why Lennar decided to sell rather than build; and Lennar didn’t respond to a request for comment.

“I can’t speak for Lennar but obviously they sold it, so it wasn’t working for them for some reason,” she said.

J.K. Dineen is a San Francisco Chronicle staff writer. Email: jdineen@sfchronicle.com Twitter: @sfjkdineen