Labour held on to Newport West in a by-election battle which saw turnout slump.
The party’s Ruth Jones took 9,308 votes, giving her a majority of 1,951 over the Tories, with Ukip in third place.
The contest was triggered by the death of veteran MP Paul Flynn and came against the backdrop of Brexit battles at Westminster.
Mrs Jones paid tribute to her predecessor in her victory speech, saying: “This by-election has taken place because of the sad passing of Paul Flynn, our friend.
“There have been many tributes to him over the weeks, but one saying stood out to me: ‘Everyone knew someone helped by Paul Flynn’. These words have been an inspiration to me during this campaign.”
The city has long been a Labour stronghold and voted Leave by a margin of 56% to 44% in the 2016 in-out referendum.
Mrs Jones had been the clear favourite to succeed Mr Flynn, who held the Newport West seat for 32 years, winning with a majority of 5,658 and more than half the vote in 2017.
Voter turnout was 37.1%, down from 67.5% in the 2017 general election, with parties blaming poor weather including rain and hail on Thursday.
The poll took place in the wake of Prime Minister Theresa May and Labour leader Jeremy Corbyn meeting face-to-face at Westminster for talks on a possible cross-party Brexit compromise.
Mrs Jones, who campaigned for Remain in the lead-up to the EU referendum, said the country should not accept a “damaging Tory Brexit” or a no-deal outcome.
Ukip’s Neil Hamilton, the highest profile name taking part in the contest, sought a return to the Commons more than two decades after being ousted as an MP in the 1997 general election following his involvement in the cash-for-questions scandal.
Mr Hamilton had hoped to benefit from the Brexit effect in the Leave-voting city and campaigned saying the by-election would provide a chance to send a clear message to Westminster over its handling of the UK’s exit from the EU.
Conservative candidate Matthew Evans, who gained 7,357 votes, had hoped to improve on his party’s performance at the 2017 general election, when the Tories finished second.
Mr Evans has been a councillor for the Allt-yr-yn ward in Newport Council for 20 years as well as serving as opposition leader, having served as mayor of the city between 2008 and 2012.
Mrs Jones is a former president of the Wales Trade Union Congress (TUC) and was defeated at two previous parliamentary elections for Monmouth in 2015 and 2017 by Conservative David Davies.
Mr Corbyn welcomed the victory, stating: “Ruth will be a fantastic successor to Paul Flynn and will take up the tireless work he carried out for this community.
“Tonight’s result sends a clear message that the people of Newport and Wales are fed up of austerity which has robbed the Welsh economy of £1 billion through needless cuts, and shows support for Labour’s alternative.”