San Francisco Supervisor Scott Wiener led fellow Supervisor Jane Kim on Tuesday in the primary election for the state Senate seat representing the city and northern San Mateo County.

The two Democrats are on track to face each other in the November runoff to replace termed-out Democratic state Sen. Mark Leno. Both were running well ahead of Republican Ken Loo in the primary, in which the top two finishers, regardless of party, advance to the general election.

With 100 percent of precients reporting Wiener had 46 percent of the votes to Kim’s 44 percent and 9.9 percent for Loo.

Because of recent changes in term limits, whoever wins in November could hold the District 11 seat for as long as 12 years.

At the Blackbird Bar on upper Market Street on Tuesday night, the mood was festive. Wiener’s supporters filled the room, sipping drinks, munching Mediterranean appetizers and posing for pictures with the candidate, who was wearing a puffy down jacket. He said he was pleased and ready to continue the campaign.

“The results show what we have always known — I’m in a good position. But this is a competitive race,” Wiener said. “I look forward to that debate — and to that fight.”

Wiener raised more money and picked up a number of prominent endorsements during the long primary campaign, including those of the state Democratic Party and Leno. Kim, however, received a late boost when she won the backing of Democratic presidential candidate Sen. Bernie Sanders.

Kim generally ran to the left of Wiener, reflecting their positions on the Board of Supervisors. Kim questioned the city’s spending on Super Bowl 50, while Wiener supported the football extravaganza.

Wiener called for the city to enforce its ban on camping as a way of dealing with homeless people’s tent cities, while Kim condemned the mayor’s sweep of tents from Division Street in early March. Kim has backed limits on corporate shuttle buses, while Wiener believes they are key to keeping cars off the streets.

The real fight will come in November. And, though Kim was trailing in the primary results, she said there is still time to win the state Senate seat. Just after 10 p.m., Kim took the stage at the Oasis nightclub South of Market before a couple hundred supporters.

With about 30 of her biggest backers, including Chinatown power broker Rose Pak, behind her, Kim sounded as if she was giving a victory speech, though she admitted the results were early.

“They said I would lose by double digits tonight, but I’m within six points,” she said. “We have been outspent 3 to 1 but we are within the cutting edge of this race in November.”

Kim finished a 20-minute speech, declaring that the city’s progressives “are taking the Demo Party back because we represent the majority of San Franciscans.”

The crowd responded by chanting loudly: “Jane, Jane, Jane, Jane.” Then the DJ cranked up the music.

Lizzie Johnson is a San Francisco Chronicle staff writer. Email: ljohnson@sfchronicle.com Twitter: LizzieJohnsonnn