Steven Senne, Associated Press
Massachusetts Democratic gubernatorial candidate Martha Coakley addresses a crowd during a campaign event, Monday, Nov. 3, 2014, in Lynn, Mass.

BOSTON — Democrat Martha Coakley phoned Republican Charlie Baker on Wednesday to concede victory in a bruising electoral fight for the Massachusetts governor's office.

Coakley had declined to concede after the ballots came in late Tuesday showing Baker with a narrow lead. But her campaign sent a statement saying she had called Baker at 8:15 a.m. Wednesday to congratulate him on his win and would address her supporters at her Somerville campaign headquarters later in the morning.

Baker, who will become the state's first GOP leader since Mitt Romney left in 2007, will replace Democratic Gov. Deval Patrick, who opted not to seek a third term in office.

Patrick said Wednesday he was turning his attention to a successful transition of power.

"Both candidates ran spirited campaigns and now it's over and we are going to turn to a smooth transition for the governor-elect," Patrick told The Associated Press.

The governor, who strongly supported Coakley, said he planned to call Baker and invite him to the Statehouse for a meeting later on Wednesday. He also planned to join Coakley for the event in Somerville.

Just under 38,000 votes separated the two, with Baker holding an edge over Coakley with 99 percent of precincts reporting, a margin of victory of about 1.7 percent.

Baker addressed his reporters at about 1:15 a.m. and said he had spoken with Coakley.

"She said she really wants to wait until the morning to see the final results and that's fine. In politics, in elections every vote counts and I'm perfectly fine with giving her until the morning to see the results come in," Baker said. "That's the way it works folks and that's the way it should work."

Baker's victory will return the state's top political office to the GOP, and with it, he earns a measure of political redemption. Baker, the former CEO of Harvard Pilgrim Health Care and a top official in the administrations of Republican Govs. William Weld and Paul Cellucci, lost to Patrick four years ago.

Coakley also had been looking for a comeback. She lost to Republican Scott Brown during the 2010 special election to fill the U.S. Senate seat left vacant by the death of Democratic stalwart Edward Kennedy.

The race was one of the closest in recent memory in Massachusetts and much closer than many observers had anticipated.

Baker had worked hard to appeal to the independent and moderate Democratic voters who are key to any statewide race in Massachusetts. He vowed to hold the lid on taxes, increase the number of charter schools and use tax credits to reward businesses that hire welfare recipients and veterans.

He raised more money than Coakley — an advantage that was magnified by the more than $8.6 million spent by outside groups supporting his candidacy, nearly all of it from the Republican Governors Association.

Three independents, Evan Falchuk, Scott Lively and Jeff McCormick, were also on Tuesday's ballot. Falchuk got a little more than 3 percent of the vote. Lively and McCormick each got about 1 percent.

Democratic Sen. Edward Markey won his first full six-year term after prevailing in a special election last year to finish out John Kerry's term. He defeated Republican Brian Herr.

The state's congressional delegation remained all-Democratic.

In a hard-fought race in the state's 6th Congressional District, first-time candidate Democrat Seth Moulton defeated Republican Richard Tisei after upsetting Democratic Rep. John Tierney in the primary.

"Now I return to public service, in a different venue but with that same commitment to serve you and to serve our great country," Moulton told supporters.

In the 9th Congressional District, Democratic Rep. William Keating fended off a challenge from Republican John Chapman.

Democratic Rep. Niki Tsongas won re-election in the 3rd Congressional District, defeating Republican Roseann Wofford.

In the race to succeed Coakley as attorney general, Democrat Maura Healey defeated Republican John Miller, becoming the first openly gay attorney general in the country.

Democratic state Auditor Suzanne Bump beat Republican Patricia Saint Aubin and Green-Rainbow member MK Merelice.

In the open contest to replace Democratic state Treasurer Steve Grossman, Democrat Deb Goldberg defeated Republican Mike Heffernan and Green-Rainbow candidate Ian Jackson.

Secretary of State William Galvin, a Democrat, fended off a challenge from Republican David D'Arcangelo and Daniel Factor of the Green-Rainbow Party.

As for ballot questions, voters rejected measures that would have repealed the 2011 casino law and expanded the state's bottle-deposit law but backed a question that would allow workers to accrue sick time.

Voters also repealed a law that ties future increases in the state's gasoline tax to inflation.

Associated Press writer Bob Salsberg in Boston contributed to this report.