With 82 percent of precincts reporting, Markey held an 8-percentage-point lead over the Republican, former Navy Seal Gabriel Gomez, and The Associated Press declared him the winner. Markey will serve 17 months; the seat will be on the ballot again in November 2014.

The race to replace Kerry, who resigned Feb. 1 to become U.S. secretary of State, began with the lessons of another Massachusetts special election fresh in both parties' minds. But the prospect of another upset fizzled after a campaign in which Democrats left little to chance, and Republicans lacked the galvanizing issue Obamacare proved to be in that 2010 race won by Scott Brown.

"The lesson from Scott Brown's accidental win in 2010 was that Democrats must never take a race for granted," said Guy Cecil, executive director of the Democratic Senatorial Campaign Committee. "Democrats came together at the local and national level, and executed a campaign plan to ensure victory."

This election failed to generate much interest. The state's chief elections officer projected record low turnout, with just over a third of 4.3 million registered voters expected to cast ballots. That would be more than 600,000 fewer than in the January 2010 special election prompted by the death of Sen. Edward M. Kennedy.

Publicly, Democrats began the campaign confident they would hold the seat with ease. But the lingering memory of that 2010 election - when the party was caught flat-footed by Brown's strong campaign - had Democrats sparing nothing to retain the seat. Vice President Joe Biden campaigned with Markey last weekend, capping a month in which President Barack Obama, former President Bill Clinton and first lady Michelle Obama all visited the Bay State.

Markey also outspent Gomez, and had support from national Democratic groups. None of the prominent conservative super PACs that spent millions on Senate races in the 2012 elections came to Gomez's aid. Only the National Republican Senatorial Committee and a group calling itself Americans for Progressive Action invested in the race.

Markey, 66, never trailed in public opinion polls, although some analysts at times listed the race as a toss-up. Gomez was seen initially as a candidate who, like Brown, had the potential to swing the votes of independent and working-class Democrats. Born in Los Angeles to Colombian immigrants, Gomez also fit the profile of the candidate Republicans have lacked as they work to repair their image among growing minority populations.

Gomez, 47, suffered in part from the fact that the race was overshadowed by other events at key moments. A special primary election in April occurred within weeks of the Boston Marathon bombings. The run-up to Tuesday's voting also competed with a playoff run from the Boston Bruins hockey team that ended in defeat just Monday night.

There were also key differences between the Republican candidates. Brown had experience in the state Legislature; Gomez was waging his first significant campaign. Brown also tapped into a burgeoning conservative movement opposed to Obama's policies - most significantly, the proposed health care overhaul - by promising to be the 41st vote in the Senate to block his agenda. Gomez took pains to distance himself from his party's most conservative elements, and even vowed to support the administration's key legislative initiatives - immigration reform and expanded background checks for gun purchases.

Gomez's initial campaign ads focused on his own personal story, and his vow to be a "different kind of Republican" who would be an answer to the dysfunction of Washington, where Markey has spent more than 36 years. But Markey managed to avoid the missteps made in the 2010 race by Democratic nominee Martha Coakley, who infamously mocked Brown's retail campaigning at Fenway Park, and even mistakenly said one of the Boston Red Sox's former star pitchers had actually played for the hated New York Yankees.

Instead, he hewed to Democratic positions that have broad support in the state, and used his legislative experience as a positive. In fact, Markey will break an 88-year-old record for longest service in the House of Representatives before winning a Senate seat. Frederick Gillette, also from Massachusetts, served in the House for 32 years - including the final six as speaker - before his election to the Senate in 1924.

Markey will replace fellow Democrat Mo Cowan, a former aide to Massachusetts Gov. Deval Patrick. Cowan served as interim senator in accordance with state law that revised the procedure to fill Senate vacancies through special elections. The outcome preserves Democrats' 54-46 advantage in the Senate, which includes two independent senators who caucus with the party.

Gomez had said in recent days that he would build off the experience of this initial campaign for another try next year, when the seat will be on the regular November ballot for a full six-year term.

With 82 percent of precincts reporting, Markey held an 8-percentage-point lead over the Republican, former Navy Seal Gabriel Gomez, and The Associated Press declared him the winner. Markey will serve 17 months; the seat will be on the ballot again in November 2014.

The race to replace Kerry, who resigned Feb. 1 to become U.S. secretary of State, began with the lessons of another Massachusetts special election fresh in both parties' minds. But the prospect of another upset fizzled after a campaign in which Democrats left little to chance, and Republicans lacked the galvanizing issue Obamacare proved to be in that 2010 race won by Scott Brown.

"The lesson from Scott Brown's accidental win in 2010 was that Democrats must never take a race for granted," said Guy Cecil, executive director of the Democratic Senatorial Campaign Committee. "Democrats came together at the local and national level, and executed a campaign plan to ensure victory."

This election failed to generate much interest. The state's chief elections officer projected record low turnout, with just over a third of 4.3 million registered voters expected to cast ballots. That would be more than 600,000 fewer than in the January 2010 special election prompted by the death of Sen. Edward M. Kennedy.

Publicly, Democrats began the campaign confident they would hold the seat with ease. But the lingering memory of that 2010 election - when the party was caught flat-footed by Brown's strong campaign - had Democrats sparing nothing to retain the seat. Vice President Joe Biden campaigned with Markey last weekend, capping a month in which President Barack Obama, former President Bill Clinton and first lady Michelle Obama all visited the Bay State.

Markey also outspent Gomez, and had support from national Democratic groups. None of the prominent conservative super PACs that spent millions on Senate races in the 2012 elections came to Gomez's aid. Only the National Republican Senatorial Committee and a group calling itself Americans for Progressive Action invested in the race.

Markey, 66, never trailed in public opinion polls, although some analysts at times listed the race as a toss-up. Gomez was seen initially as a candidate who, like Brown, had the potential to swing the votes of independent and working-class Democrats. Born in Los Angeles to Colombian immigrants, Gomez also fit the profile of the candidate Republicans have lacked as they work to repair their image among growing minority populations.

Gomez, 47, suffered in part from the fact that the race was overshadowed by other events at key moments. A special primary election in April occurred within weeks of the Boston Marathon bombings. The run-up to Tuesday's voting also competed with a playoff run from the Boston Bruins hockey team that ended in defeat just Monday night.

There were also key differences between the Republican candidates. Brown had experience in the state Legislature; Gomez was waging his first significant campaign. Brown also tapped into a burgeoning conservative movement opposed to Obama's policies - most significantly, the proposed health care overhaul - by promising to be the 41st vote in the Senate to block his agenda. Gomez took pains to distance himself from his party's most conservative elements, and even vowed to support the administration's key legislative initiatives - immigration reform and expanded background checks for gun purchases.

Gomez's initial campaign ads focused on his own personal story, and his vow to be a "different kind of Republican" who would be an answer to the dysfunction of Washington, where Markey has spent more than 36 years. But Markey managed to avoid the missteps made in the 2010 race by Democratic nominee Martha Coakley, who infamously mocked Brown's retail campaigning at Fenway Park, and even mistakenly said one of the Boston Red Sox's former star pitchers had actually played for the hated New York Yankees.

Instead, he hewed to Democratic positions that have broad support in the state, and used his legislative experience as a positive. In fact, Markey will break an 88-year-old record for longest service in the House of Representatives before winning a Senate seat. Frederick Gillette, also from Massachusetts, served in the House for 32 years - including the final six as speaker - before his election to the Senate in 1924.

Markey will replace fellow Democrat Mo Cowan, a former aide to Massachusetts Gov. Deval Patrick. Cowan served as interim senator in accordance with state law that revised the procedure to fill Senate vacancies through special elections. The outcome preserves Democrats' 54-46 advantage in the Senate, which includes two independent senators who caucus with the party.

Gomez had said in recent days that he would build off the experience of this initial campaign for another try next year, when the seat will be on the regular November ballot for a full six-year term.