Liberal Democrat Helen Morgan, representing England's third biggest party, overturned a Conservative majority of almost 23,000 votes from the last election to win Thursday's contest.
The election in North Shropshire, a rural area of northwest England, was called after the former Conservative member of Parliament resigned amid a corruption scandal.
The result will heap pressure on Johnson just two years after he was re-elected with a seemingly unassailable 80-seat majority in Parliament.
But his authority has been dented in recent weeks by allegations that he and his staff attended Christmas parties last year while the country was under lockdown, efforts to shield an ally from allegations of illegal lobbying and suggestions that he improperly accepted donations to fund the lavish refurbishment of his official residence.
Against this backdrop, supporters and opponents are questioning Johnson's handling of the pandemic after coronavirus infections soared to records this week as the highly transmissible omicron variant swept through the UK.
“Tonight, the people of North Shropshire have spoken on behalf of the British people,” Morgan said in her victory speech. “They said loudly and clearly, 'Boris Johnson, the party is over. Your government, run on lies and bluster, will be held accountable. It will be scrutinised, it will be challenged, and it can and will be defeated.”
-With PTI inputs