The developer of a 315-unit apartment complex, which sparked a years-long political battle in the East Bay city of Lafayette, said he would bring it back if voters killed a ballot measure to put 44 single-family homes on the same lot.

And, unofficial results showed Measure L was indeed headed for defeat.

That would open the door for developer O’Brien Homes to revive its original plan to build the Terraces of Lafayette, a large complex on Deer Hill Road, about a mile away from Lafayette BART Station.

“If Measure L fails, we will resume processing the application for the Terraces,” O’Brien Homes President Dennis O’Brien said Thursday.

It’s a surprise twist in a housing skirmish that’s pitted San Francisco activists against a vocal faction of Lafayette residents, who want to preserve the city’s bucolic character. Lafayette is known for its ranch houses, sport utility vehicles and streets with no sidewalks.

O’Brien was careful to note that some ballots were still dribbling in, and the election results wouldn’t be certified until the end of the month.

Election returns on Friday afternoon had 46 percent of voters supporting the 44-homes plan, and 54 percent against. That outcome is unlikely to change.

Three years ago, the co-founder of San Francisco’s Yes in My Backyard — or YIMBY — group sued Lafayette for scrapping the Terraces plan because of neighborhood opposition, offering the 44 houses as an alternative.

The East Bay city became a colorful symbol for what became a statewide “Sue the Suburbs” campaign. The idea: Force bedroom communities to build dense housing.

“It has a good school district, it’s on a BART line and it’s exclusionary,” said Sonja Trauss, co-founder of YIMBY and co-executive director of its legal arm, the California Renters Legal Advocacy and Education Fund, which filed the suit.

The 44-house compromise — which included a dog park, tot lot and soccer field — got a chilly reception not only from the YIMBYs, but from neighbors who coalesced to form an antidevelopment group called Save Lafayette. They said 44 houses on a hill would cause traffic congestion along Pleasant Hill and Deer Hill roads and ruin the air quality.

The area just across from Acalanes High School has long been a point of contention, said former Lafayette Mayor Anne Grodin. Traffic flowing to and from Highway 24 clots the Springhill and Reliez Valley neighborhoods that abut Pleasant Hill Road, and residents oppose any development that would bring in more cars.

“These folks have been mobilized for years,” Grodin said, noting that neighbors have loudly objected even when the city proposed road improvements. In that area, something as simple as a right-turn lane could be perceived as a major disruption.

So, the parcel went to court. It became the focus of a land use debate that in many senses was also a culture war.

The YIMBYs settled their case last year. Save Lafayette filed a separate lawsuit and won on appeal, successfully forcing a ballot referendum in June that put the 44-home project to voters.

Now both sides are claiming victory.

“This is the outcome that Save Lafayette wants,” said Gary Garfinkle, an attorney for the group.

Trauss also celebrated the outcome, albeit for the opposite reason. Now that the 44-house project had been knocked down, Lafayette would return to its “default” option: 315 apartments.

“The Save Lafayette folks, they either don’t know or don’t believe that if they kill the 44 single-family homes, then this other project is going to happen,” she said. “What they don’t realize is that times have changed, and you can’t just willy-nilly disapprove housing.”

Trauss and her co-executive director, Victoria Fierce, said they were ready for another spirited fight.

“Let’s organize and get people to raise a ruckus out there,” said Fierce, who lives in downtown Oakland. She blames stagnant development in Lafayette and other inland areas for causing gentrification in the inner city.

“We have this city-by-city view of the housing shortage, but it needs to be a regional thing,” she said.

Fierce hinted that if the YIMBYs aren’t able to rally much support in Lafayette, they might recruit people from Oakland and San Francisco to show up at Lafayette City Council meetings. If officials refuse to approve the Terraces apartment complex, YIMBY can always file another lawsuit, she said.

The prospect of more legal gamesmanship makes Grodin shudder.

“Whatever happens after this vote is going to cost the city buckets of money, because there will be many more lawsuits,” she said.

Grodin endorsed Measure L, calling it a “reasonable number of houses that would only have a moderate impact on traffic.” She and Lafayette City Manager Steven Falk challenged the YIMBY perception that Lafayette has failed to build enough apartments.

“Sometimes we get painted as a community that is not supportive of housing, and that’s just not accurate,” Falk said. He pointed out that in the past five years the city has approved or begun building about 500 units, mostly in its downtown core.

Michael Griffiths, a member of the Save Lafayette group, declined to comment. He said he is waiting for the election results to be made final.

After suing Lafayette, YIMBY focused on other cities, including Berkeley, San Mateo, Dublin and Sausalito. They are contemplating a new lawsuit in the Silver Lake neighborhood of Los Angeles.

But the open slopes on Deer Hill Road still beckon, said lawyer Ryan Patterson, who represented the group in the Lafayette suit.

He sees the Terraces as “an opportunity for moderate-income families to build a life for themselves in the Bay Area.”

Rachel Swan is a San Francisco Chronicle staff writer. Email: rswan@sfchronicle.com Twitter: @rachelswan