British Prime Minister Boris Johnson has vowed to listen and learn but refused to quit, after his Conservatives suffered crushing defeats in two parliamentary elections and a staunch ally stepped down.

In a pointed resignation letter to Mr Johnson, party chairman and cabinet member Oliver Dowden said "somebody" had to shoulder the blame for "recent events".

That was widely seen as a reference to "partygate" and other scandals dogging the prime minister, who only narrowly survived a no-confidence vote this month among Tory MPs.

But Mr Johnson framed the election setbacks as mid-term blues for the Conservatives, as Britain contends with inflation reaching double-digit levels not seen since the 1970s, rising poverty and strikes.

"I'm not going to pretend these are brilliant results. We've got to listen. We've got to learn," he told reporters in Rwanda, where he is attending a Commonwealth summit.

"But I genuinely, genuinely don't think the way forward in British politics is to focus on issues of personalities, whether they are mine or others," he added.

"The way forward is to make arguments to people about change and improvement that we are delivering. And that is what I was elected to do."

After his visit to Rwanda, Mr Johnson travels to Germany and then Spain for G7 and NATO summits.

He is not due back in Britain until late next week and is facing some calls to cut the trip short to deal with the by-election fallout.

In the Tiverton and Honiton constituency, southwest England, the party saw its 2019 general election majority of more than 24,000 votes wiped out by the centrist Liberal Democrats, in one of the biggest upsets of UK electoral history.

The main Labour opposition regained the parliamentary seat of Wakefield, in northern England, in a further sign of its resurgence after Johnson triumphed in 2019 on a vow to "get Brexit done".

Since then, the impact of Brexit and the Covid pandemic have worsened the economic picture.

Opinion polls suggest widespread disgust at Mr Johnson's leadership arising from lockdown-busting parties held in Downing Street.

The victorious Liberal Democrat candidate, Richard Foord, said voters in Tiverton and Honiton had sent a "shockwave through British politics".

"It's time for Boris Johnson to go, and go now," he said.

Labour's newly elected MP for Wakefield, Simon Lightwood, told Mr Johnson: "Your contempt for this country is no longer tolerated."

Tony Travers, politics professor at the London School of Economics and Political Science, said it was "almost inconceivable" that Johnson would willingly bow out.

But the results at opposite ends of England showed a "pincer movement" by Labour and the Liberal Democrats on Tory strongholds.

"And that will significantly worry many Conservative MPs," he said.

The reasons for the two by-elections were emblematic of Tory troubles.

The former MP for Tiverton and Honiton had to step down after he was seen watching pornography on his phone in parliament.

In Wakefield, the MP quit after he was convicted of sexually assaulting a 15-year-old boy.

The "porn MP", Neil Parish, rejected Mr Johnson's attempts to deflect blame after the Tories lost his rural area of southwest England for the first time since the early 19th century.

"It became a referendum on Boris Johnson and what is happening nationally," he told BBC television.

Under current party rules, the prime minister should be safe from another leadership vote for 12 months.

But senior MP Geoffrey Clifton-Brown, who sits on the "1922 committee" of Tory backbenchers, indicated that the rules could change.

Mr Johnson will have to defend himself anew to the party in the coming days, he said on BBC radio.

"We will then, in the parliamentary party, have to make a judgment as to whether we think that is a satisfactory explanation, or whether we should actually take steps to have a new prime minister."

Mr Dowden was an early backer of Mr Johnson's bid to unseat Theresa May as Conservative leader in June 2019.