LOUISVILLE, KY. -- Former Marine pilot Amy McGrath overcame a bumpier-than-expected Kentucky primary to win the Democratic U.S. Senate nomination Tuesday, fending off progressive Charles Booker to set up a bruising, big-spending showdown with Republican Senate Majority Leader Mitch McConnell.

Voting ended June 23, but it took a week until McGrath could be declared the winner due to the race's tight margins and a deluge of mail-in ballots. The outcome seemed a certainty early in the campaign but became tenuous as Booker's profile surged as the Black state lawmaker highlighted protests against the deaths of African Americans in encounters with police.

It was a narrow victory for McGrath. With 99% of precincts reporting Tuesday afternoon, she had an 11,832-vote advantage over Booker out of nearly 531,000 votes cast. Several other candidates attracted tens of thousands of votes. McConnell, a key ally to President Donald Trump, already breezed to victory in the GOP primary in his bid for a seventh term.

Kentucky switched to widespread absentee voting amid the coronavirus pandemic, and election officials needed days to count ballots. In Lexington, the state's second-largest city, about 6,000 absentee ballots were thrown out on technicalities ranging from unsigned envelopes to detached security flaps, said Fayette County Clerk Don Blevins.

Since last summer, McConnell and McGrath looked past their primaries to skirmish with each other, and now those attacks will intensify heading into the fall campaign.

Declaring victory, McGrath reached out to Booker's supporters to try to unite the party for the challenge ahead against McConnell, who has dominated Kentucky's political landscape for decades.

“There is far too much at stake,” McGrath said in a statement. “The differences that separate Democrats are nothing compared to the chasm that exists between us and the politics and actions of Mitch McConnell. He's destroyed our institutions for far too long.”

By mid-afternoon Tuesday, Booker's campaign had not publicly commented on the outcome.

McConnell campaign spokeswoman Kate Cooksey said McGrath's narrow victory was proof that her campaign is damaged heading into the general election. Cooksey portrayed McGrath as a “tool” for the national Democratic establishment and said the challenger was out of step with Kentucky with her support for abortion rights and “government-run health care.”

McGrath has raised prodigious amounts of campaign cash, capitalizing on the wrath national Democrats have for McConnell. It places her in a position to go toe-to-toe with the always-well-funded McConnell.

Despite her advantages, McGrath sweated out her victory against the hard-charging Booker.

Booker's long-shot bid surged amid the national eruption of protests against police brutality. He joined demonstrations in his hometown of Louisville to demand justice for Breonna Taylor, who was fatally shot by Louisville police in her own home. Booker gained the backing of leading national progressives as he supported a universal basic income and Medicare for All - ideas that McGrath resisted.

McGrath charted a more moderate course inside Democratic politics. She supports adding a public health insurance option as part of the Obama-era Affordable Care Act and supports expanded access to Medicare for people 55 and older.

She portrays McConnell as an overly partisan, Washington insider who exemplifies what's wrong with national politics. She accuses McConnell of undermining labour unions, awarding tax cuts for the wealthy and cozying up to pharmaceutical companies while people struggle to afford prescription drugs.

McConnell accuses her of being too liberal for Kentucky on issues ranging from abortion to border security. He promotes his work with President Donald Trump - who remains popular in Kentucky - to appoint conservatives to fill federal court seats. McConnell also plays up his Senate leadership role and his ability to steer federal money back to the Bluegrass State.

Trump could turn into a focal point in the Senate race.

McConnell led the effort to defend the president after House Democrats impeached him. McGrath has said she would have voted to convict Trump on both impeachment counts. She accused of the GOP-led Senate of lacking “the guts” to put a check on “out-of-control presidential power.”