Rachel Maddow reports the breaking news that Democratic Congressman Ed Markey has won the Massachusetts senate seat vacated when John Kerry became Secretary of State, defeating Republican challenger Gabriel Gomez.

Secretary of State John Kerry's former Senate seat will stay in Democratic hands as longtime Massachusetts Rep. Ed Markey handily defeated Republican Gabriel Gomez in Tuesday’s special election.

The win is an important one for Democrats who avoided a potential embarrassment and now retain a 54-46 margin in the Senate, with a chance to gain back one more seat in an October special election in New Jersey.

“I’m going to the U.S. Senate to stand up for you, and for the values that I've always believed in: honesty, fairness and equality,” Markey said during his victory speech Tuesday night. "I pledge you, that I will be a senator who will fight for you, every hour, on every vote, on every issue to make progress for you and your families."

Since winning the nomination in a shortened election, Markey, a 37-year congressional veteran, held the upper-hand in the heavily-Democratic state but his party took no chances with nightmare memories of having been burned just two years ago.

In the January 2010 contest to fill the seat of the late Ted Kennedy, Republican Scott Brown shocked the political world by riding a rising GOP wave and discontent for health care reform to victory.

Still sore from that defeat, Democratic groups invested heavily to boost Markey, combining to spend more than $5.2 million on his behalf, compared to the $3 million Gomez and predominately one outside super PAC did on his behalf.

And Democrats spared no surrogate, with President Obama, Vice President Joe Biden, First Lady Michelle Obama, and former President Bill Clinton all trekking to the Bay State to stump for Markey. Arizona Sen. John McCain appeared on behalf of GOP nominee Gomez, as did Brown who lost his seat to Democratic Sen. Elizabeth Warren in 2012.

In a memo Tuesday, the Democratic-aligned Senate Majority PAC, which spent over $1 million on TV ads for Markey, said they “began working late last year with numerous partners, in Massachusetts and nationally, to prevent another sneak attack that allowed Scott Brown to win in the January 2010 special election.”

Only Americans for Progressive Action, a new GOP-aligned super PAC backed by a wealthy California winemaker, came to Gomez’s aid, spending over $700,000 on ads. But in the end, it was not enough, and Gomez campaign strategists were openly frustrated that other flush outside groups, such as American Crossroads, had sat on their hands.

In his concession speech Tuesday night, Gomez said his campaign "went up against the machine" and was "massively outspent." But he also said he would make no excuses for his loss and that both he and Markey are better people for having gone through the contentious race.

To some national Republicans Gomez was just the type of candidate the GOP needed to push as they looked to expand their base after a disappointing 2012 election cycle – a young, moderate Hispanic veteran and businessman. In debates and on the campaign trial, Gomez underscored key points where he differed with his party, including on climate changing and supporting gay marriage and expanded background checks for gun purchases.

Gomez also argued he could be a key bipartisan broker in the immigration debate, boasting Tuesday morning that he wanted to make the working reform group a “Gang of Nine.”

Markey countered in the media that Gomez would simply be another GOP vote in the Senate. The Democrat highlighted Gomez’s opposition to banning assault weapons and tax cuts. Though Gomez, a Catholic, says he’s personally anti-abortion, he has said he would not work to overturn existing law, but Markey has argued he’d vote to confirm Supreme Court justices who would overturn the law. Gomez, a wealthy former investment banker has also faced criticism over a quarter-million tax break he claimed on his home.

But in the end, lightning didn’t strike twice for the GOP. The economy is improving, health care faces a rocky but ongoing implementation, and the state’s Democratic and independent voters seem unconvinced to send a vote to Washington to undermine their newly-minted Democratic senator and popular president.

Though even many Democrats privately grumbled Markey didn’t have the most rigorous campaign schedule and was not the most exciting candidate, the dean of the state’s congressional delegation is now headed to the Senate.

President Obama also congratulated Markey following his victory, praising the lawmaker's leadership during his years in Congress.

"The people of Massachusetts can be proud that they have another strong leader fighting for them in the Senate, and people across the country will benefit from Ed's talent and integrity," Obama said in a statement.

NBC's Andrew Rafferty contributed to this report.