Martha Coakley announces her concession of the race for Massachusetts governor to Charlie Baker Wednesday.

BOSTON — Flanked by campaign staff and supporters, Democrat Martha Coakley Wednesday morning announced her concession of the race for Massachusetts governor to Republican Charlie Baker.

“He could not have been more gracious when I called him to say congratulations," Coakley said at a press conference at her campaign headquarters in Somerville. “It was an extraordinary privilege to serve as the nominee … to meet the folks I did everyday.”

Baker held a narrow lead over Coakley that was too close to call Tuesday night. The lead held up Wednesday morning, when returns showed him with a nearly 40,000-vote margin.

Coakley, the attorney general, called Baker at 8:15 a.m. Wednesday to congratulate him on a victory that came amid a wave of Republican wins across the nation. She then called on supporters to rally behind him.

“Although Charlie is going to be the next governor, I feel like we both won,” she said. “I believe that we both learned from this race, about ourselves and Massachusetts."

Coakley was joined at the press conference by an all-star cast of Massachusetts Democrats including Gov. Deval Patrick, Sen. Elizabeth Warren and Maura Healey, who will replace her as attorney general after winning Tuesday.

Coakley fought back tears as she talked about female candidates running for elected office.

“For every woman who didn’t get that promotion or who ran and didn’t win, I say get right back out there,” she said. “I am challenging you to never give up.”

Coakley's running mate, lieutenant governor hopeful Steve Kerrigan, also thanked supporters.

"This campaign didn't end as we had hoped but the challenges we face are far from over," he said. "This campaign stood for all the right things. And we will continue to fight."

This was Baker's second run for the governor's office, which has been in Democratic hands since 2006, when Patrick was first elected. A former health care executive, Baker narrowly lost to Patrick in 2010. Patrick didn't seek a third term this year.

Coakley, who suffered an embarrassing loss to Republican Scott Brown in a 2010 U.S. Senate race, was seeking to become the first woman to win the governor’s office in a general election.

Polls showed Baker with a slight lead over Coakley headed into the election, with independents Evan Falchuck, Jeff McCormick and Scott Lively trailing behind.

Secretary of State Bill Galvin’s office said preliminary estimates show more than 2.2 million voters cast ballots — roughly half of the state’s 4.2 million registered voters.

Gov.-elect Baker was expected to meet with Gov. Patrick this afternoon to begin the process of selecting a new cabinet.

"I have no doubt it will be a seamless transition,” Baker told reporters at a televised press conference at the Seaport Boston Hotel, less than an hour after Coakley’s concession speech. "I think at this point we’re anxious to get started with what happens next … to hire a great team.”

Outside the Coakley press conference, supporters said they were upset that the Democrat wasn't able to pull off a victory.

"I really felt it was a close race but that we had a chance," said Erin Batista of Revere.

Christian M. Wade covers the Massachusetts Statehouse. He can be reached at cwade@cnhi.com. Follow him on Twitter: @cmwade1969