"Not every fight is a fair fight," Gomez said in his concession speech. "Sometimes you face overpowering force. We were massively overspent. We went up against literally the whole national Democratic Party. And all its allies."
Markey outspent Gomez throughout the race, and Republicans were unable to match a well-oiled Democratic field organization in an election that saw relatively light turnout in much of the heavily Democratic state.
Kerry left the Senate this year after being confirmed as U.S. secretary of state. Markey will fill out the remainder of Kerry's term, which expires in January 2015, meaning that another Senate election will be held a year from November.
Despite Markey's lengthy career in Congress, he will become the state's junior senator to Elizabeth Warren, who has been in office less than six months after defeating Brown last November.
Markey led in pre-election polls but said Tuesday when he voted with his wife that there was no overconfidence in his organization. President Barack Obama, former President Bill Clinton and Vice President Joe Biden visited Massachusetts over the final two weeks of the campaign to shore up support for him.
Obama congratulated Markey on his victory Tuesday and said he looked forward to working with him to strengthen the U.S. economy and protect the middle class.
"He's earned a reputation as an effective, creative legislator, willing to partner with colleagues across the aisle to make progress on the issues that matter most," Obama said in an emailed statement.
Gomez had said while voting Tuesday in Cohasset, where he lives with his wife and children, that the election was about choosing the future over the past and what he called Markey's failure to take on the important issues.
In Cambridge, Lori Berenson, 51, said she voted for Markey mainly because she was skeptical of one of Gomez's main campaign pitches: his request for just 17 months in office.