The losses, one in the Conservatives' traditional southern heartlands and in a northern English industrial seat won from Labour in the last election, suggest the broad appeal Johnson presented to win the 2019 election may be fracturing.
Fears that Johnson could have become an electoral liability may prompt lawmakers to move against him again after months of scandal over COVID-19 lockdown parties at a time when millions are struggling with rising food and fuel prices.
Johnson has so far resisted pressure to resign after he was fined for breaking lockdown rules at his Downing Street office.
This month, he survived a vote of confidence by Conservative lawmakers, though 41% of his parliamentary colleagues voted to oust him, and he is under investigation by a committee over whether he intentionally misled parliament.
“I think as a government I’ve got to listen to what people are saying,” Johnson told broadcasters in Kigali after the results. “We’ve got to recognise there is more we’ve got to do,” he added.
Following the losses in Tiverton and Honiton in southwest England, and Wakefield in the north, Conservative Party Chairman Oliver Dowden resigned in a carefully worded letter that hinted he might believe Johnson should take responsibility.
“We cannot carry on with business as usual,” he said. “Somebody must take responsibility and I have concluded that, in these circumstances, it would not be right for me to remain in office,” added Dowden, a long-time ally of Johnson. Some Conservatives blamed him for running poor campaigns in both the voting areas by ignoring local concerns.
Johnson responded by saying he understood Dowden's disappointment but “this government was elected with an historic mandate just over two years ago” and he would continue to work to that end.
A Conservative party source said Johnson was not concerned about further resignations from his cabinet team of top ministers and took a swipe at the media for what they called “misreporting” of lockdown parties. Finance minister Rishi Sunak said "we all take responsibility" for the defeats.
But the explanations offered by Johnson and his team may do little to ease frustration in the Conservative Party.
Several Conservative lawmakers tweeted support for Dowden, saying he was not to blame for the results in messages that suggested resurgent dissent against Johnson's leadership.
Although under his party's rules Johnson cannot face another confidence motion for a year, lawmakers fearing for their own futures may try to force a change to bring about a second vote.
That might take time. It would entail changes to the committee that represents Conservative lawmakers who do not have government jobs.
A wave of cabinet resignations could also be another route to force Johnson out before the next national election, expected in 2024. It could be called earlier, but US bank Citi said in a note the likelihood of that was “limited”.
The by-elections were triggered by the resignations of Conservative lawmakers - one who admitted watching pornography in parliament and another found guilty of sexually assaulting a teenage boy.
The party lost its large majority of more than 24,000 votes in Tiverton and Honiton to the centrist Liberal Democrats.
"If Conservative MPs don't wake up, I think at the next election, the voters will send them packing," the Liberal Democrats' leader, Ed Davey, said.
In the parliamentary seat of Wakefield in northern England, the main opposition Labour party won.
"This result is a clear judgment on a Conservative Party that has run out of energy and ideas," Labour leader Keir Starmer said.
Johnson led the Conservatives to their biggest majority in three decades at the 2019 national election, winning in traditionally Labour-voting areas in north and central England.
But the loss of Wakefield could indicate that his ability to repeat that trick has been compromised.