Insurgent candidate Amy McGrath, a retired Marine fighter pilot, pulled off an upset victory in a Democratic primary House race in Kentucky on Tuesday night, defeating the party establishment candidate.

McGrath emerged from a three-person race in Kentucky’s Sixth District, beating her main challenger, Lexington Mayor Jim Gray. The race was called around 8 pm, with McGrath winning with 46 percent of the vote to Gray’s 42.3 percent. Gray, a millionaire who ran for US Senate against Rand Paul in 2016, had the backing of the Democratic Congressional Campaign Committee.

McGrath was born in Kentucky but only recently returned to the state; she spent the past couple of decades serving in the Marine Corps as a fighter pilot. With help from a viral campaign announcement video highlighting her years of military service, McGrath went from an outsider and first-time candidate with no name recognition to the Democratic nominee.

Throughout the campaign, McGrath positioned herself as a change agent, part of a new generation of young candidates and Congress members, and touted her lack of political experience — the very thing her opponents attacked her for.

“Recruiting the same types of big-city, older millionaires is not the future,” McGrath said in a January interview with Vox. “Especially in the Democratic Party, we cannot keep relying on a staple of rich white people, old men, to save the Democratic Party.”

But McGrath’s opponents attacked her outsider status as evidence that she didn’t know the district she was running in. Having recently moved to Kentucky from the DC area, McGrath struggled to name the counties of three rural communities when asked about them at a debate.

In the runup to Tuesday night, Gray’s campaign released its first negative ad about McGrath, hitting her for moving back to the state to run.

SIREN: @JimGrayCongress is airing 1st negative ad of the #KY06 race, hitting @AmyMcGrathKY as a carpetbagger ahead of Tuesday’s primary pic.twitter.com/dOmTsyJpDu — Ally Mutnick (@allymutnick) May 18, 2018

“Now she’s running for Congress to represent the one place she’s never lived: here,” a narrator says on the ad. “In fact, she moved here from Maryland just last year to run for Congress. We honor Amy McGrath’s service, but shouldn’t she live here for a while before she tries to represent us?”

The ad immediately received pushback from veterans groups like VoteVets and some sitting members of Congress who are veterans, such as Rep. Ted Lieu (D-CA).

“You can elevate yourself, but don’t attack another Dem,” Lieu tweeted. “One reason @AmyMcGrathKY lived in a different place is because she was serving our nation in Afghanistan & Iraq flying F-18 combat missions. Stop attacking her military service. Take your ad down.”

Dear @JimGrayCongress: You can elevate yourself, but don't attack another Dem.



One reason @AmyMcGrathKY lived in a different place is because she was serving our nation in Afghanistan & Iraq flying F-18 combat missions.



Stop attacking her military service. Take your ad down. https://t.co/0KHvbV5K8i — Ted Lieu (@tedlieu) May 19, 2018

Gray’s ad demonstrated another thing: In the last few weeks of a race that was supposed to be an easy win for him, the Lexington mayor saw McGrath as a serious competitor.

McGrath now faces Republican Andy Barr, and she’ll likely have help from national Democrats

Even though things started out tense between McGrath and national Democrats, this likely won’t be another Laura Moser oppo memo situation in Texas. McGrath wasn’t happy with the DCCC for backing Gray early on; her campaign had also been in talks with the organization before it added Gray to its Red to Blue list.

“It’s disappointing to me that they would do that, especially after the talk of them wanting more veterans and more women, and more first-time candidates,” Moser told me in January. “To have done that, it kind of shows you the real disconnect between the national Democratic Party and places like Kentucky. And the key is, we have forgotten, as a party, how to win the Midwest and the South.”

Even after the McGrath campaign’s initial furor at the DCCC backing Gray, National Journal’s Ally Mutnick reported the campaign has kept in regular contact with the DCCC to show them internal polling numbers that had McGrath ahead of Gray.

McGrath has also shown herself to be a very capable fundraiser; she’s raised about $2 million as of May, as opposed to the $1.3 million Gray raised (although Gray still had more cash on hand).

In other words, even as McGrath positioned herself as the outsider candidate, she was making sure to keep up a good relationship with national Democrats, whose support she’ll need in order to triumph over Barr in the fall.

The ultimate test in November comes down to whether McGrath can convince Trump voters to cast their ballots for her instead of Barr. The district leans Republican, and many of its rural counties voted for the current president in 2016. But it contains 100,000 more registered Democratic voters. In other words, it’s prime Trump country.

Barr will face a tough election no matter what. Democrats have already mounted credible challenges to him in past years but fell short on fundraising. That’s different this year. McGrath and Gray fundraised millions between the two of them in the primary; they have real fundraising chops. Barr will also have to defend his votes for Obamacare repeal and GOP tax cuts.

Now she’s made it through the primary, McGrath is betting that her anti-establishment brand will carry her to Washington in an election year that’s shaping up to be a Democratic wave.