Image copyright Getty Images Image caption Republican Karen Handel praised Donald Trump in her victory speech

US Republicans have won a closely contested congressional election in Georgia seen by many as a referendum on Donald Trump's presidency.

Karen Handel retained the Atlanta seat with 53% of the vote, against 47% for her Democratic rival Jon Ossoff.

The vacancy arose when Tom Price left to become health secretary. He had won the seat with a 23 point lead.

In South Carolina, Republican Ralph Norman beat Democrat Archie Parnell in a solidly conservative area.

President Trump congratulated both candidates.

On the victory in suburban Atlanta, he tweeted: "Congratulations to Karen Handel on her big win in Georgia 6th. Fantastic job, we are all very proud of you!"

Long months ahead for Democrats - Anthony Zurcher, BBC News, Washington

Democrats were desperate to mark Tuesday's race as the moment the political tide began to turn in their favour. Instead, they woke up on Thursday to a president crowing about "his" triumph on Twitter.

One race is of little consequence in determining who controls the House of Representatives, but the Georgia election - with its record-breaking cost and red-hot spotlight - matters. A lot.

Democrats will surely be discouraged. They may be less willing to pour money into future races. The party's Bernie Sanders populist wing is second-guessing Mr Ossoff's decision to campaign as a moderate - heralding the possibility of more intra-party warfare in the days ahead.

Republicans, on the other hand, can exhale. They'll feel more confident in pushing through their legislative agenda without ballot-box consequences.

Nervous incumbents considering retirement in the face of a coming electoral wave may stick around. And, at least for now, their president gets a welcome bit of good news after weeks of Russia-related headaches.

November will bring another round of electoral tests - including key governors races in Virginia and New Jersey - that will be on friendlier terrain for Democrats.

Until then, it's going to be a long few months for those on the left.

Image copyright Getty Images Image caption Jon Ossoff was a political newcomer

Georgia's sixth district is a traditionally safe Republican seat but Democrats had hoped to capitalise on the president's low approval ratings.

Spending on candidates was put at $56m (£44m), making it the costliest congressional election in US history.

Democrats have already suffered narrow defeats in Kansas and Montana this year.

Addressing jubilant supporters, Ms Handel thanked key Republican figures, including President Trump.

"I need to also thank Speaker Ryan and the House leadership and so many of the members across this country. And a special thanks to the President of the United States of America," she said.

Mr Ossoff told his supporters they had provided "a beacon of hope for people here in Georgia, for people across the country, and for people around the world".

Media playback is unsupported on your device Media caption The Georgia vote is the most expensive congressional election in history

He also said they should celebrate having 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," Mr Ossoff said.

In April, he narrowly failed to win the 50% needed to secure outright victory in a first round, forcing the run-off against Ms Handel.

She had come a distant second in the first round, but the Republican vote had been split among 11 candidates.

Republicans believed the run-off would favour them in an affluent seat they have held since 1979.

They also believed that last week's shooting of Republicans on a Virginia baseball field would count in their favour at the polls.

The suspected gunman was a Democratic supporter and a Republican advert that sought to politicise the attack was condemned by Ms Handel.

Image copyright Twitter

The South Carolina fifth-district seat, vacated when Mick Mulvaney became Mr Trump's budget director, had been expected to be an easy win for Republicans.

The Republicans have so far staved off defeats by the Democrats this year.

In April they narrowly defended a deeply conservative Kansas seat vacated when Mr Trump appointed Congressman Mike Pompeo to lead the CIA.

Last month, Republican Greg Gianforte won a special congressional election in Montana, despite being charged with assaulting a UK reporter.