Amy McGrath, a retired Marine Corps fighter pilot recruited by national Democrats to mount a long-shot bid against Senate Majority Leader Mitch McConnell, has prevailed in her party’s Senate primary in Kentucky.

McGrath held off a late surge from Charles Booker, a state legislator who tapped into the energy of the movement for racial justice and won endorsements from several high-profile liberals on the national stage.

The race had remained too close to call on Election Day last week as many absentee ballots had yet to be counted. Booker held a narrow advantage over McGrath in a large field based on early and in-person totals released a week ago.

But McGrath made up ground as more votes were tallied, according to updated results, and benefited from early voting. On Tuesday, Edison Research projected that McGrath would win the nomination. She had 45.4 percent of the vote compared with Booker’s 42.6 percent, with more than 99 percent of precincts reporting.

In a statement Tuesday, McGrath said she was “humbled” to have won the Democratic nomination and said she “can’t wait to get started in sending [McConnell] into retirement and finally draining the toxic Washington political swamp that he built.”

She also congratulated Booker “for his very impressive result” and urged party unity in seeking to oust McConnell (R-Ky.).

“There is no doubt that Charles tapped into and amplified the energy and anger of so many who are fed-up with the status quo and are rightfully demanding long overdue action and accountability from our government and institutions,” McGrath said. “Sadly, our system is broken. We need to elect people who will have the courage to meaningfully tackle the socioeconomic, legal and educational inequities that continue to prevent true equality in our country.”

McConnell, who is seeking a seventh term, easily prevailed in the Republican primary last week.

In a statement Tuesday afternoon, Booker conceded the race but said, “I think it’s safe to say we shocked the world.”

“From the hood to the holler, we stood our ground, and went toe to toe against the big donors, pundits, and D.C. politicians saying it wasn’t possible to run the kind of campaign I’ve always believed Kentucky deserves,” he said. “We went from being down 50 points in the polls to falling just short of a tie. While I’m disappointed, I’m so proud of us, and I’m still hopeful.Hundreds of thousands of Kentuckians left behind by Mitch McConnell came together to demand a better future, and a better government

In the closing weeks of the race, Booker tapped into the anger over police killings of African Americans, including Breonna Taylor, who was shot eight times after Louisville police officers used a battering ram to enter her apartment.

He also fully embraced a liberal agenda, including Medicare-for-all and the Green New Deal, while McGrath offered somewhat more moderate policy prescriptions.

McGrath drew the backing of Senate Minority Leader Charles E. Schumer (D-N.Y.), which helped bolster her fundraising. By the start of June, she had raised more than $40 million.

Booker drew support from some leading liberal luminaries, including Sen. Bernie Sanders (I-Vt.) and Rep. Alexandria Ocasio-Cortez (D-N.Y.).

In the primary, the rejection of roughly 6,000 absentee ballots in Fayette County highlighted the strict rules Kentuckians must follow to ensure their mail-in votes are counted.

County Clerk Don Blevins Jr. said in virtually every case, the voter made an error that invalidated the ballot under state law, including failing to sign and seal both the outer and inner ballot envelopes.

He added that while the 6,000 figure seems large, it represented just over 7 percent of the total number of returned absentee ballots.

“I think Kentucky’s absentee ballot laws need an overhaul,” Blevins said. “This election has really revealed just how strict we are. We could do better.”

Asked if voters need more guidance about the process before November, Blevins said his team had already done “an awful lot” to make sure county residents knew the rules.

“At some point, the voter is going to have to take a little responsibility,” he said. “. . . We’ll try again in the fall, but [voter error] happens every single election.”

Starting with an announcement video nearly a year ago, McGrath has sought to cast McConnell as out of touch with his Kentucky constituents and has blamed him for dysfunction in Washington.

Since then, McConnell’s campaign has treated the well-funded McGrath as the likely Democratic nominee, seeking to cast her as too liberal for Kentucky.

Moments after news organizations called the race for McGrath on Tuesday, McConnell spokeswoman Kate Cooksey issued a statement saying McGrath “does not represent Kentucky values.”

“Extreme Amy McGrath is lucky to have gotten out of the primary with a victory, but her reputation sustained significant damage all across Kentucky,” Cooksey said. “McGrath is just another tool of the Washington Democratic establishment who has no idea what matters most to Kentuckians.”

During the campaign, McConnell has touted his influence in Washington. In an ad this spring, he highlighted his role in the passage of a $2.2 trillion stimulus bill responding to the coronavirus pandemic. McConnell was shown striding through the Capitol and standing behind President Trump as he signed the measure into law.