In a first test of the political terrain ahead of an uncertain 2020 race, Republican Dan Bishop edged out Democrat Dan McCready in the closely watched, do-over special election in North Carolina's 9th Congressional District, according to an Associated Press projection. The decision brought to a close the final undecided contest of the 2018 midterm elections.

Interested in 2020 Elections?

Add 2020 Elections as an interest to stay up to date on the latest 2020 Elections news, video, and analysis from ABC News.

The toss-up race, in a Republican stronghold that voted for President Donald Trump by 12 points in 2016, was the result of election fraud by a Republican operative hired by 2018 GOP candidate Mark Harris. Despite Harris narrowly defeating McCready, the North Carolina State Board of Elections threw out the results and ordered a new contest after a months-long investigation. With Harris bowing out, Bishop took up the mantle for Republicans.

Bishop led McCready, 51% to 49%, with 96% of precincts reporting -- a margin of about 4,000 votes.

Trump was quick to tout the victory -- and claim credit -- just minutes after the projected victory for Bishop. Trump said, "Dan Bishop was down 17 points 3 weeks ago. He then asked me for help, we changed his strategy together, and he ran a great race."

Dan Bishop was down 17 points 3 weeks ago. He then asked me for help, we changed his strategy together, and he ran a great race. Big Rally last night. Now it looks like he is going to win. @CNN & @MSNBC are moving their big studio equipment and talent out. Stay tuned!

Democrats’ hopes of winning the seat were boosted by the fact that, even with the presence of fraud marring the results, McCready only lost by 905 votes. But Trump, the party’s heavyweight, made an eleventh-hour push for Bishop -- rallying his base in Fayetteville to boost the Republican's campaign.

"We are behind you 100 percent," Trump told a packed crowd in Fayetteville's Crown Theater on the eve of the election. "North Carolina, in our country, got hit the hardest, that was a little bit of a surprise, but one thing about North Carolina is you can take it and you’ll build it quickly and you’ll build it beautifully and you’ll be back sooner than anybody ever thought."

A Democratic victory in the contest would have not only been a major upset for Republicans in a district long considered out of reach for Democrats, but it could have also potentially stifled the GOP's hopes of reclaiming a House majority in 2020.

Sean Rayford/Getty Images

Dan McCready waits to greet voters outside of a polling station during the special election against Republican Dan Bishop, Sept. 10, 2019, in Monroe, North Carolina.

For the GOP, the costly, competitive race was seen by some as a must-win after the resounding rebuke of their agenda and Democrats' 40-seat gain in 2018.

Bishop, who sponsored the state’s controversial "bathroom bill" that barred transgender individuals from using public bathrooms consistent with their gender identity, closely tied himself to the president to garner support among his base.

"We've all watched as the Democratic Party, the socialist Democrat Party, seeks the president's destruction everyday," state Sen. Bishop said at Monday's rally. "We've seen a dishonest media serve as their handmaidens and their allies in that mission. We've watched as the greatest fighter ever to occupy the White House has brushed them all off."

The district sits on the border of South Carolina and currently stretches from Charlotte's suburbs to more rural areas east of the city after being redrawn in 2016 -- and is representative of the exact areas Trump needs to win to secure his reelection.

A Republican loss "reinforces the dynamics coming out of the 2018 election that Republicans are increasingly struggling in urban and suburban districts," Eric Heberlig, a political science professor at the University of North Carolina at Charlotte, told ABC News last month. "It's a message that ... districts that have traditionally been theirs, and they still should have the advantage in, are still breaking against them, and similar districts going into 2020 are at severe risk."

Republicans saw their grip on the district, and similar ones across the country, unwind in the midterms, in part due to Trump's rhetoric driving away suburban voters, particularly women.

In 2019, the congressional contest provided an early preview of where this key voting bloc stands -- as both Democrats and Republicans brace for a competitive 2020 presidential race with Trump back on the ballot.

"North Carolina's 9th District is such an interesting race, because this is our first test of suburban voters after the midterms," said Leah Askarinam, an analyst at Inside Elections.

A Trump campaign official told ABC News they see the special election as a “dry run.”

In a sign of Republican concerns over a potential loss, it wasn't just Trump who headed to the district Monday. Vice President Mike Pence campaigned with Bishop earlier in the day on the opposite end of the district.

"Dan is a rock solid conservative," he said to one caller while making calls for Bishop at a makeshift call center inside a Courtyard by Marriott outside Charlotte. "He is the right Dan."

Last week, the Trump campaign also donated the maximum amount of $2,000 to Bishop.

But Trump isn’t the only 2020 candidate who waded into the race. Former Vice President Joe Biden, appearing to use the contest as a proxy for a general election against Trump, backed McCready last month -- as he did last May during the midterms -- and has been fundraising for the Democrat in the weeks leading up to the election.

"If we can win this election -- in a ruby red district -- it will be proof that we can defeat Trump and replace him with Joe Biden," the Biden campaign wrote in one email to supporters after Trump announced his Fayetteville rally.

In his marathon campaign that began in the spring of 2017, McCready, a Marine Corps veteran, bet on a message of "country over party" in this off-year election.

The day before the election, McCready told a crowd of veterans, "We don’t care about your background or your political party, we care about putting our country first. Whether it’s lowering health care costs or strengthening public schools, we’ll work across the aisle to get it done."

He’s also a proven fundraiser, having raised $6.7 million for his 2018 race. This year, McCready continued to widen the fundraising gap between him and his Republican rival, raking in nearly $415,000 in just the last couple weeks, compared to about $106,000 raised by Bishop. He’s raised a total of $5.4 million so far this year, compared to Bishop’s $2.1 million.

The contest has seen more outside spending than any other race so far this year, except for the presidential election -- with more than $18.3 million flowing into the contest on both sides as of Monday.

Nearly $10.8 million of outside money has been either spent or secured by outside party committees, super PACs and politically active nonprofits, with more than $6.8 million supporting Bishop and $3.9 million favoring McCready.

But it's not the majority status in the House that's drawing millions into the obscure special election in North Carolina, Heberlig said -- it's the parties and their allies' chance to win "bragging rights" to say that they won in a place where the outcome was uncertain, and one of the few opportunities ahead of 2020 to test their messages to see what resonates with voters.

The Democratic Congressional Campaign Committee, the campaign arm of House Democrats, modeled their strategy after Pennsylvania Congressman Conor Lamb's successful win in the 18th Congressional District by focusing on turnout early and hit the airwaves late. The DCCC, along with the newly formed pro-House Democratic group House Majority Forward, have spent just about $2.3 million.

The House Republican campaign committee and the House GOP leadership linked super PAC Congressional Leadership Fund together have rolled out nearly $5.5 million in a campaign blitz. Republicans have centered on a theme that casts McCready as "Greedy McCready" and aligns him with "radicals" in Washington, such as House Speaker Nancy Pelosi, Rep. Alexandria Ocasio-Cortez, D-N.Y., and Sen. Bernie Sanders, I-Vt.

Among the outside groups investing in the district is the Progressive Turnout Project, a national grassroots field organization, which has been focusing their turnout efforts on inconsistent voters that could be crucial to a McCready victory. They have also dropped nearly $300,000 in the expensive race.

"The places where we can have the greatest impact is a district where there is a field margin," said Alex Morgan, the executive director, in an interview with ABC News. "That's the perfect sort of environment for us to have a value add in terms of amplifying the voices of folks who may not otherwise get to the polls."

In this tough contest, Heberlig warns, the outcome will come down to turnout.

"In a special election like this, it is turnout that matters," Heberlig said. "That probably favors Republicans, because their voters are much more reliable than Democratic voters are."