It began with a March rally in San Francisco’s West Portal neighborhood, where participants held “Jane Kim” signs in one hand and umbrellas in the other to beat back the morning drizzle.

Kim, a supervisor in a downtown district who is running for mayor on June 5, gave a speech deriding a housing bill by state Sen. Scott Wiener, her political rival. The bill would prevent local governments from rejecting proposals for tall, dense buildings near transit hubs and lines, a notion that has infuriated owners of single-family homes and neighborhood activists on the west side of town.

Kim said SB827 would quilt the city with “seven-story luxury condos,” a message that played well with George Wooding, president of the Coalition for San Francisco Neighborhoods, who was at the rally. He lives in Mid-town Terrace, between Sutro Tower and Laguna Honda Hospital.

“I don’t want the state to start tinkering with all the planning of San Francisco,” Wooding said, adding that Kim’s stand against SB827 “fits the west side like a glove.”

Her opposition appears to be propelling her campaign — and deepening the rift between Kim and Wiener — with nine weeks to go until the June 5 special election. West side voters tend to elect moderates, but they’ve found common ground with Kim, a progressive, on this issue. Moderates favor free-market housing solutions, whereas progressives lean toward higher amounts of affordable housing and extracting concessions from developers.

When asked Thursday if Wiener had handed her a campaign gift, Kim responded with a laugh, “He’s certainly given us an issue to debate.”

He also gave Kim a way to court “older, wealthy white voters in West Portal — what we think of as the true NIMBYs of the city,” said political consultant David Latterman, who worked for Wiener during his successful 2016 state Senate race against Kim.

“Her hook is ‘don’t build,’” Latterman continued. “And if she gets to needle Scott, well, that’s a bonus for her.”

Kim said she timed the rally to happen the same week as a Board of Supervisors committee hearing on SB827, which — even though she is a member of that committee — she did not attend. She also said she picked West Portal because she had another event nearby the same morning, “so it was convenient to do it there.”

In a tight mayoral race among three candidates who have similar views on most things, housing and land use have become the major points of contention.

Supervisor London Breed has emerged as the moderate, pro-housing candidate — she got the sole endorsement of San Francisco’s Yes In My Backyard group, which advocates building homes at all price points everywhere in the city. Mark Leno, who has receded a bit in recent polls, is trying to play the middle. He told The Chronicle’s editorial board that he’s against Wiener’s legislation, though he praised the general concept of putting housing near transit.

Kim, whom polls show to be neck-and-neck with Breed, has adopted a shrewd strategy: She appears to be unifying her base of tenant coalitions on the east side of town with more conservative homeowners in places like Balboa Terrace and Forest Hill.

Those two constituencies have joined hands to fight Wiener’s bill, which would require cities to allow four- to eight-story apartment or condominium buildings in any residential area that’s within a half mile of a major transit station. San Francisco Assemblyman Phil Ting is a co-sponsor. It would apply statewide.

Of her opposition to the bill, Kim said: “It’s a pure giveaway to developers. We are simply enriching the pockets of landowners and developers without getting anything in return.”

The San Francisco Tenants Union says SB827 would cause displacement and prevent cities from setting affordable housing requirements for developers, although the bill explicitly says it would not interfere with those requirements. Wealthy residents fear it would allow developers to put giant apartment towers in the city’s low-rise enclaves, where single-family homes predominate.

Wiener views Kim’s marrying of these two demographics as political opportunism.

“I hope it doesn’t work,” he said in an interview Thursday, noting that Kim’s positions on other issues, such as her reluctance to remove homeless tent camps, are “not aligned with west side voters.”

The issue has provided Kim inroads into prosperous northern parts of the city as well. Supervisor Catherine Stefani, whose district includes the Marina and Cow Hollow, said she’s received 560 emails opposing SB827, compared with about 72 emails supporting it.

It’s scrambled the traditional moderate and progressive factions, said Nathan Ballard, a Democratic strategist and adviser to Mayor Mark Farrell. He emphasized that he was not speaking on Farrell’s behalf.

“This is not left and right — it’s NIMBY versus YIMBY,” Ballard said. “There isn’t a neighborhood activist in San Francisco who is going to let Sacramento decide what goes in next door to them. People in Bernal Heights or Cow Hollow don’t want their neighborhood to turn into Manhattan.”

Opponents who packed the rancorous supervisors committee hearing last month compared the bill to “an undemocratic power grab” and a “hydrogen bomb” that will “blow San Francisco to bits.” Supporters say it will help unclog freeways, lower carbon emissions and stabilize housing prices.

The pro and anti sides clashed Tuesday when they held dueling protests outside City Hall, which at points devolved into shouting and shoving. Later that day, the Board of Supervisors voted 8-3 in favor of a resolution to oppose Wiener’s bill. Kim voted for the resolution; Breed, who supports the bill’s intent, was among the dissenters.

To some political observers, this issue is one of the few that sets the mayoral candidates apart.

“All of our debates come down to land use,” said Laura Foote Clark, executive director of the Yes In My Backyard group.

The state bill has become a huge campaign for Wiener, a former supervisor from the Castro who won the bruising 2016 state Senate contest against Kim by a narrow margin. Centrist constituencies, including older white west side voters, helped secure his victory.

Those voters are educated and engaged, and turn out in high numbers, Latterman said.

“If you’re going to pander, you pander to folks who are going to vote,” he added. “And those folks are going to vote.”

Wiener endorsed Breed on Monday at a ceremony in the Castro near Leno’s campaign office. But he also endorsed Leno months before, and some interpreted his recent backing of Breed as a sign of how much the housing debate — and SB827 in particular — has shaped this mayor’s race since as a candidate she is most favorable toward it.

Others saw it as Wiener’s way of saying, “Anyone but Jane.”

The June election is likely do-or-die for Kim, who will be termed out of her supervisor seat at the end of this year. If she loses, she could fade out of city politics. But if she wins, she’ll be a rising star and a bigger threat to Wiener moving forward.

Some speculate that Kim and Wiener may spar for House Minority Leader Nancy Pelosi’s seat at some point or for a higher state office. Wiener’s name has also been floated as a potential candidate for mayor in 2019 or 2023.

“Absolutely,” said Jason McDaniel, an associate professor of political science at San Francisco State University. If the two politicians don’t compete in a future mayoral contest, they could go head-to-head for lieutenant governor, he said.

“It’s highly likely there will be a rematch one of these years,” Ballard said.

Wiener and Kim both downplayed the idea.

“I’m not focused on Jane’s political future, or mine,” Wiener said. “I’m focused on doing my job as a state senator and on getting a superb mayor for San Francisco — and I think it would be Leno or Breed.”

Similarly, Kim said on Thursday she has “not thought past June 5.”