The 30-second ad features clips from a speech Obama gave at a Boston campaign rally for Markey earlier this week, in which he praises Markey's commitment to the middle class and touts his support for gun control measures.
"I've gotta have folks with me who care as passionately about these things as I do. That's who Ed Markey is. I need Ed Markey in the United States Senate," he says in the ad.
Obama appeared in the state just two weeks out from Election Day as part of a take-no-chances strategy from Democrats concerned about a repeat of the 2010 surprise upset that sent Republican Scott Brown to the Senate.
Markey has led in nearly every poll of the race, but Republican Gabriel Gomez has managed to keep his lead down to single digits, prompting fears of a come-from-behind surge from the Republican.
Democrats hope Obama's endorsement will buoy Markey, as he's still widely popular in the state, and he defeated Republican Mitt Romney, Massachusetts's former governor, by 23 points in November.
Gomez has been heavily outspent on air by the Markey campaign, but an outside spending group that bills itself as moderate is going on air with a $700,000 buy for the Republican in the final weeks of the campaign.