Ad spending in Georgia’s Sixth Congressional District race has reached nearly $40 million, easily cementing the congressional contest as the most expensive of its kind in U.S. history, according to new data shared with NBC News.

The numbers, compiled by Advertising Analytics, show that Republicans have narrowly edged out Democrats in total ad spending for the primary and runoff elections in the high-stakes congressional showdown, with GOP organizations spending a total of $21 million on the airwaves to defend the reliably Republican seat vacated by now-Health and Human Services Secretary Tom Price. Democrats, boosted by record-setting fundraising by candidate Jon Ossoff, have spent a total of $18.7 million on the air.

The mammoth cost of the special election contest dwarfs past records — previous high-dollar races topped out around $20 million in television and radio spending — and it highlights how the race has become a national proxy war between the two parties. Despite its history as a Republican bastion, the suburban Atlanta district’s affluent and well-educated population selected Donald Trump by the narrowest of margins in 2016, making the special election a particularly ripe target for Democrats desperate to notch a win against the president.

Ossoff, who has smashed fundraising records by amassing millions in mostly out-of-state donations, is the top spender on either side of the aisle, shelling out $13.6 million on TV and radio advertisements since the beginning of the primary election. That’s compared to just $2.3 million in spending by Republican Karen Handel, who secured her spot in the June 20 runoff election in an earlier primary contest in April.

But Republican outside groups have compensated for Handel’s spending deficit. The National Republican Congressional Committee has spent about $6.5 million on advertisements, while the Paul Ryan-affiliated Congressional Leadership Fund has paid out an additional $4.8 million.

That high level of spending is particularly striking because Price, who held the seat from 2004 until this year, walloped his latest Democratic opponent by more than 20 points, and both John McCain and Mitt Romney carried the area by double digits.

Democratic Party groups have spent far less on ads in the race, leaning instead on Ossoff’s record-setting war chest. The Democratic Congressional Campaign Committee has spent $4.3 million, and the House Majority PAC — the primary Super PAC charged with electing Democrats to the House —has spent only about $254,00 so far. (Another group, Patriot Majority USA, which has partnered with the House Majority PAC, has put up an additional $281,000.)

The Democratic reliance on Ossoff's spending — with nearly three-quarters of all Democratic ad spending coming directly from the candidate's coffers — also comes with an important benefit for the pro-Ossoff side. Because candidates receive more favorable rates for ads than issue groups, Democrats have actually been able to air more ads despite being outspent by the GOP overall.

Advertising Analytics found that about 60 percent of the 24,000 ads aired during the race have been funded by Democrats, compared to 40 percent paid for by Republicans.

And Democrats have had even more of an advantage during the two-candidate runoff election, with the pro-Ossoff side airing about twice as many ads as the pro-Handel side.