Former Rep. Ann Kirkpatrick Ann KirkpatrickArizona Rep. Tom O'Halleran wins Democratic primary Arizona Rep. Ann Kirkpatrick wins Democratic primary Cook shifts 20 House districts toward Democrats MORE (D-Ariz.) won the Democratic primary in Arizona’s 2nd District, making a political comeback in a key swing seat that the party needs to win in November.

Kirkpatrick defeated Democrat Matt Heinz, an emergency room physician and former state legislator who ran to her left in a contentious primary battle for Rep. Martha McSally Martha Elizabeth McSallyThe Hill's Campaign Report: Presidential polls tighten weeks out from Election Day Mark Kelly: Arizona Senate race winner should be sworn in 'promptly' New ABC/WaPost poll finds Trump edging Biden in Arizona, Florida MORE’s (R-Ariz.) open seat. She won with 41 percent of the vote, compared to Heinz's 31 percent, The Associated Press projected with less than 1 percent of precincts reporting.

ADVERTISEMENT

Kirkpatrick vacated her more moderate seat in Arizona’s northern 1st District to run for Senate in 2016. She ultimately lost to the late Sen. John McCain John Sidney McCainAnalysis: Biden victory, Democratic sweep would bring biggest boost to economy The Memo: Trump's strengths complicate election picture Mark Kelly: Arizona Senate race winner should be sworn in 'promptly' MORE (R-Ariz.) that year.

The former congresswoman’s decision to switch to the Tucson-based 2nd District in order to return to the House opened her up to immense criticism from Heinz, who called her a carpetbagger and challenged her residency.

Heinz had been the Democratic nominee in the 2nd District in 2016, but failed in his bid to unseat McSally even as the district voted for Hillary Clinton Hillary Diane Rodham ClintonFox News poll: Biden ahead of Trump in Nevada, Pennsylvania and Ohio Trump, Biden court Black business owners in final election sprint The power of incumbency: How Trump is using the Oval Office to win reelection MORE.

Heinz even funded a lawsuit that challenged Kirkpatrick’s residency as listed on her campaign paperwork. A judge ultimately ruled that Kirkpatrick could appear on Tuesday’s ballot.

The doctor also made waves by comparing Kirkpatrick’s desire to run again to a "meth addiction" in an interview with National Journal, which drew major backlash.

The campaign was also marked by sharp attacks lobbed from both camps about their respective positions on gun control.

Heinz attacked Kirkpatrick for previously boasting of an "A" rating from the National Rife Association, though she argued that her stance changed following the Tucson shooting that wounded former Rep. Gabrielle Giffords (D-Ariz.) in 2011.

Still, Democrats stuck with Kirkpatrick as their best hope of winning. Kirkpatrick had the support of important Democratic groups, including the Democratic Congressional Campaign Committee and EMILY’s List, while Giffords also supported her.

Kirkpatrick also significantly outraised Heinz, who spent about $400,000 of his own money on the primary.

Kirkpatrick is considered a more moderate Democrat since she once represented a more GOP-leaning district, and she is hoping to win over the same kind of independent voters in November.

Heinz ran on a more progressive platform, including support for "Medicare for all."

Kirkpatrick goes into the general election with about $335,000 cash on hand, just above Peterson's $246,000.

Arizona's 2nd District is a top swing seat that Democrats have been targeting in their quest to flip the 23 seats they need to retake the House. Clinton won it by nearly 5 points in 2016, though the same district reelected McSally by 14 points. The race is rated as "lean Democratic" by the Cook Political Report.

McSally vacated her seat to run for Senate, winning the GOP primary on Tuesday.