Labour had held both seats since their creation but was forced to defend them when two former frontbenchers, Tristram Hunt and Jamie Reed, resigned as MPs.

Copeland, created in 1983, and its predecessor constituency Whitehaven have returned Labour MPs since 1935.

Media captionGareth Snell: A city dubbed by some the capital of Brexit has once again proved to the world we are so much more than that

Mrs Harrison, who had been joined by Prime Minister Theresa May on the campaign trail, got 44.3% of the vote, increasing the Conservatives’ vote share by more than 8%. She overturned a Labour majority of more than 2,564 to take the seat by 2,147 votes – a swing of more than 6%.

Professor John Curtice, of Strathclyde University, said the Copeland result was the best by-election performance by a governing party in terms of the increase in its share of the vote since January 1966.

In her victory speech, Mrs Harrison said: “It’s been very clear talking to people throughout this campaign that [Labour leader] Jeremy Corbyn doesn’t represent them.

“They want a party which is on the side of ordinary working people, which will respect the way we voted in the referendum and which will build a country which represents everyone. That’s why they voted for me tonight.”

BBC assistant political editor Norman Smith said the result was an extraordinary achievement for a governing party after seven years of austerity and would strengthen the prime minister’s grip on British politics.

Mr Corbyn said Labour’s “message was not enough to win through in Copeland” but hailed victory in Stoke as a “decisive rejection of UKIP’s politics of division and dishonesty”.

He added: “Labour will go further to reconnect with voters and break with the failed political consensus.”

In Stoke-on-Trent, UKIP had hoped to capitalise on voters’ leanings towards Brexit – the area voted strongly to leave the EU in June.

Analysis

Image copyrightReuters

By BBC political correspondent Tom Bateman in Copeland

This victory marked an astonishing political moment for the Conservatives.

The last Tory MP to represent this area was born in 1879. Their newest, Trudy Harrison, swept away 80 years of Labour dominance here, saying hers was the party for working people.

For a governing party to take a seat vacated by the opposition in a by-election is exceptionally rare.

This was the best such performance in half a century when measured by the increase in vote share. It will be hailed in Downing Street.

The result followed a bruising campaign, fought over jobs in the nuclear industry and hospital services. Labour’s defeated candidate Gillian Troughton was ushered out of the count venue without speaking to reporters.

This outcome will renew questions over Jeremy Corbyn’s leadership. He has promised to reconnect with voters. He may have to try in the face of further opposition from his own MPs.

Both the Labour and UKIP candidates had tough moments during their campaigns, with Mr Snell apologising over old social media posts about women appearing on television and Mr Nuttall facing a backlash over false claims he lost close friends in the Hillsborough tragedy.

But in his victory speech, the new Labour MP Gareth Snell said voters had “chosen the politics of hope over the politics of fear”.

“This city will not allow ourselves to be defined by last year’s referendum and we will not allow ourselves to be divided by the result,” he said.

He said the result was “a victory for the whole Labour Party and Labour movement”.

‘Not going anywhere’

However Labour’s share of the vote was 37% – slightly down on the 39.3% it got in 2015.

UKIP got 24.7% of the vote and the Conservatives, who came a close third, 24.4% – both slightly higher than their 2015 vote shares.

Speaking to journalists after the result, UKIP leader Mr Nuttall said his party’s “time would come”.

“There’s a lot more to come from us,” he said.

“We are not going anywhere, I’m not going anywhere.”

Analysis: UKIP’s missed chance

Image copyrightGetty Images

Image caption
Mr Snell’s UKIP opponent Paul Nuttall casts his vote

By BBC political correspondent Chris Mason in Stoke

The questions facing Labour in Copeland are tumbling UKIP’s way here in Stoke.

A party whose very success in achieving the thing they were set up to achieve, Brexit, brought with it a blunt question – what is the point of them now?

Labour MP Jack Dromey, who ran Mr Snell’s campaign, said: “I think as we win we need necessary humility because there is a view that Labour is no longer listening in the way it should do.

“I think what we have done in this community is precisely to do that.

“Are we yet a credible alternative government? No we’re not. But tonight is a decisive moment.”

The by-election results mean the government’s majority is now 12 – the same as it was immediately after the general election, as the Conservative’s new Copeland seat makes up for the one they lost to the Lib Dems in the Richmond Park by-election. The working majority is 16.