The concession, two days after polls closed, ends a race that has overshadowed politics at City Hall for nearly a year, pitted many friends and political allies against one another and attracted huge money — and sometimes nasty attacks — from outside groups, including tech investors and unions. While Chiu was favored to win since the campaign’s outset, Campos mounted a formidable challenge, and the race remained too close to call for two days after election day.

But Thursday afternoon, the San Francisco Department of Elections — which is continuing to tally votes — released updated numbers showing Chiu’s consistent lead had jumped to about 3,700 votes, or 4 percentage points.

After studying the numbers, Campos conceded about 7 p.m. Thursday. Both candidates confirmed the concession, with Chiu saying that the supervisors — whose campaigns often turned nasty — “had a positive conversation and agreed to work together in the future for the good of San Francisco.”

“I am incredibly humbled to be elected to serve in the state Assembly and I look forward to making sure that Sacramento delivers for San Francisco on the challenges of our time, from housing affordability and schools to transportation and the environment,” Chiu said. “After six years working to make City Hall more effective by bringing all sides together to get things done, I look forward to the opportunity to do that in our state Capitol for San Francisco and all of California.”

Chiu — a more moderate, but still liberal, Democrat — focused his message from the beginning on compromise, painting himself as a pragmatic politician who could bring people together. Backed by construction trade unions and business groups, Chiu also benefited by substantial outside spending by big-name tech investors including Ron Conway, an ally of Mayor Ed Lee’s. Lee endorsed Chiu in the final weeks of the campaign.

Chiu’s election leaves not only an open supervisor seat for the mayor to fill, but sets up a fight for who will be the next board president.

The loss is a tough blow for the city’s progressives, who had pinned their hopes on Campos as a way to maintain a far-left presence in Sacramento now that Assemblyman Tom Ammiano is termed out. Campos focused his message on economic inequality, campaigning as a progressive standard bearer who would fight for working families in Sacramento. The nurses and public employee unions backed his candidacy, turning out to not only campaign for Campos but to support his policies at City Hall.

In a statement, Campos — an openly gay man who ran as far as he could to Chiu’s left — invoked gay rights leader Harvey Milk’s concession in an Assembly race 42 years ago, thanking all the people who worked on his campaign.

“As I write this, my thoughts are with Supervisor Harvey Milk,” he stated. “Forty-two years ago Harvey made a similar call when he lost his own race for the 17th Assembly District by fewer than 4,000 votes. ... Yet the message that is most associated with him is that of hope. Right now my heart is filled with hope.

“Let’s continue this movement,” he said. “Let’s sharpen and articulate our vision for a just San Francisco, build with both our traditional allies and those who also question the direction this city is going and get back to the hard work.”

While Chiu was thought to have an edge in the race to represent San Francisco’s eastern side, Campos put up a tough fight, coming within four points of his opponent in the primary and, after a disappointing fundraising period over the summer, rallying in the fall to raise nearly $500,000 and push the race into a dead heat in pre-election polls. All told, the candidates and their outside supporters spent more than $4.5 million this year — much of it on nasty mailers.

Both men pledged Thursday to leave the heated nature of the campaign behind and work together, as Chiu said, “for the good of our city.”

“I applaud Supervisor Campos and his supporters on their passion and hard work, and we do have healing to do,” Chiu said. “Our city continues to face new challenges and we need to work together to move San Francisco forward.”