Markey had a lot on his mind. He has held elected office for his entire professional life, but Kennedy’s decision threatened to end his five decades-long political career. The senator contemplated what to do, what his parents would do, and concluded he would run for reelection, according to his campaign manager John Walsh.

Markey won his first race to the state House in 1972 shortly after finishing law school and rose to the US House of Representatives and the Senate. After that initial victory, Walsh said, Markey’s dad gave his son some advice based on his own personal experience: “You got to be like the milkman, you got to deliver every day.”

Last year, Markey’s decision could’ve been described as a fool’s errand. A Kennedy has never lost a race in Massachusetts, a state that wants its senators to be stars, if not president. In 2018, the Democratic Party chose Kennedy to respond to President Donald Trump’s 2018 State of the Union address. Weeks before Kennedy’s announcement in 2019, a Suffolk University poll showed the congressman up by 14 points.

But the past year has shown off Markey’s under-appreciated political prowess. Kennedy pitched himself as the embodiment of generational change; Markey wore retro-hip Nikes and aligned himself with New York Rep. Alexandria Ocasio-Cortez, the party’s youngest, brightest phenom. Kennedy attempted to poke holes in Markey’s long record, including his votes for the Iraq War, NAFTA, the Patriot Act and the 1994 crime bill; Markey positioned himself as the progressive champion on a number of issues from climate change to health care.

Well-educated voters, as well as young people, whites and the wealthy, prefer Markey, according to a recent University of Massachusetts Lowell poll, which showed the senator leading the race beyond the margin of error.

Kennedy’s critics have raised a simple question that the congressman says he doesn’t hear on the trail: why are you running? At a Markey event in Framingham on Sunday, Michael Hugo claimed that Kennedy is “all ego” and “entitlement,” calling the divisive Democratic primary a “distraction” from the fight against Trump.

The congressman believes that the coronavirus pandemic has hurt his campaign more than Markey’s in reaching voters, which could’ve helped him in rebutting those attacks. Kennedy has knocked the senator for not being been home in Massachusetts enough and has pledged to be everywhere; the pandemic has limited anyone going anywhere.

But in the final weeks of the campaign, Kennedy has crisscrossed the state. On August 21, after making some 20 stops in about 24 hours, meeting fishermen, frontline Covid-19 workers and Latino voters, Kennedy tweeted out a photo at 3:48 a.m. ET of a meeting with Massachusetts Bay Transportation Authority workers. During that whirlwind tour, House Speaker Nancy Pelosi endorsed Kennedy, noting the congressman’s countrywide campaign to help the Democrats flip the House in 2018.

In an interview on Sunday, Kennedy said that in the communities racked by the pandemic he’s been to lately — ticking off Chelsea, Everett, Revere and Brockton — the question he hears is not about why he ran but instead, “what we can do to help?”

“The fact is that I think a United States senator from Massachusetts can do a lot to help,” said Kennedy. “I respect the senator, but I don’t think he’s given us anywhere near the dedication and attention that communities like Grove Hall here in Boston and so many other parts across the state, need and deserve.”

One of the most audacious moves of Markey’s campaign was to flip on its head the famous call to action by the late President John F. Kennedy, the congressman’s great uncle who also served the state as senator. “We asked what we could do for our country. We went out, we did it,” said Markey in the now-viral ad. “With all due respect, it’s time to start asking what your country can do for you.”

The ad was concocted by the Sunrise Movement, a grassroots group focused on climate change who backed Markey early on for his co-authorship of the Green New Deal, according to spokesperson Stevie O’Hanlon.

The senator’s support of that plan has helped endear Markey, 74, to voters less than half his age.

“He is fighting for the stuff that is going to affect our generation,” said Ellie Petit at a rally in Natick.

On Sunday, Markey tied the ad to the fact that roughly half of all Black American adults do not have jobs. “They are feeling real pain,” Markey told CNN. “So, it’s not about one family, it’s about every family. Let’s make sure every family gets what they need from our country.”

Kennedy has made racial justice a focal point of his campaign and held advantages in polling with people of color. He has hit Markey for doing little for the family of D.J. Henry, a Black man who was shot and killed by a White police officer 10 years ago. (Markey told CNN he has apologized to the family, adding, “We should now focus on moving forward to get justice” for them.)

A recent Kennedy ad shows a picture of DJ’s parents, who have criticized Markey, and connects his work for them to his family’s.

“Joe Kennedy knows how a legacy is earned: in communities where a leader lives and works, in quiet conversations with people grieving and struggling, in the fight he and his family made for generations,” says the ad’s narrator. “For health care for all, for jobs and opportunity, for racial justice — long promised but never delivered. It’s a fight in his blood.”

The ad includes clips of Kennedy’s deceased relatives, including his grandfather, the attorney general Robert F. Kennedy, as well as his great uncles, President Kennedy and Massachusetts Sen. Ted Kennedy. The congressman did not so directly tie himself to them until Markey brought up his family, and still seems uncomfortable doing so.

On Sunday, Kennedy said he’s “inspired by their service, and what they meant for this country,” but, “If you vote for me, you’re gonna get me.”