SANDY SPRINGS, Ga. (Reuters) - Georgia Republican Karen Handel won the most expensive congressional race in history on Tuesday, avoiding a Democratic upset in a race that was widely seen as a referendum on President Donald Trump.

By a margin of 52 percent to 48 percent, the former Georgia secretary of state defeated Democrat Jon Ossoff, a political newcomer who sought to wrest control of a suburban Atlanta district that has elected Republicans to Congress since the 1970s.

The election will not significantly change the balance of power in Washington, where Republicans control the White House and both chambers of Congress.

But it could give Republicans a boost in confidence as they struggle to advance health and tax legislation that has been bogged down by infighting and investigations into whether Trump’s campaign colluded with Russia in last year’s presidential election.

Handel said at her victory rally that she knew it was going to “require all hands on deck” for Republicans to hold on to the district.

“Tonight I stand before you, extraordinarily humbled and honored at the tremendous privilege and high responsibility that you ... have given me,” Handel told a boisterous crowd that chanted Trump’s name.

Ossoff and Handel both tried to focus on local issues and avoided mentioning Trump, whose approval rating sits at 37 percent, according to Reuters/Ipsos polling.

Slideshow ( 15 images )

But that did not stop Trump from weighing in on Twitter, urging voters to support Handel before the election and celebrating her victory afterward.

“Fantastic job, we are all very proud of you!” he posted Tuesday night.

Spending on the race reached at least $57 million, nearly twice the previous record, according to the Center for Responsive Politics, a watchdog group. The special election was held to fill the seat vacated by Tom Price after Trump appointed him as secretary of the U.S. Department of Health and Human Services.

Democrats celebrated the fact that they had turned a conservative stronghold into a competitive district.

“We showed the world that in places where no one thought it was even possible we could fight (that) we could fight,” Ossoff told supporters.

But the defeat was sure to prompt soul-searching in a party that is shut out of power in Washington and has steadily lost influence at the state level in recent years. Despite spending more than $30 million, Ossoff lost the district by a wider margin than Democrat Hillary Clinton in the 2016 presidential election.

Slideshow ( 15 images )

Democrats also lost a special election in neighboring South Carolina on Tuesday, where Republican Ralph Norman easily prevailed over Democrat Archie Parnell in a seat formerly held by Republican Mick Mulvaney, who is now serving as Trump’s budget director.

Democrats are 0 for 4 in congressional elections this year, having earlier lost races to fill vacant seats in Kansas and Montana.

“All the Fake News, all the money spent = 0,” Trump wrote on Twitter.

Republicans, meanwhile, can now breathe a sigh of relief with the knowledge that they can still win in the kind of affluent, educated districts that often favor Democrats - even with a president who has divided voters in their own party.

“Do I agree 100 percent with what he does? God, no. But I believe he has the country’s best interests at heart,” said Jessica Podalsky, who voted for Handel on Tuesday morning.