The triumph in Thursday's vote is a boost for Johnson and his strategy during the COVID-19 crisis. A furore over the financing of a lavish refurbishment of his Downing Street apartment had no obvious impact on the result.
"There's no hiding from the fact this is a shattering result for Labour, absolutely shattering," Labour lawmaker Steve Reed, a member of Starmer's top team, told the BBC.
"It tells us that the pace of change in the Labour Party has not been fast enough. We need to quicken it up."
The Conservatives described it as an historic day.
The by-election, which takes place outside the normal parliamentary election cycle, was triggered by the resignation of a Labour lawmaker in March, and is one of dozens of votes which took place on Thursday.
Labour had held Hartlepool for decades. Election analysts said it was the biggest swing of votes to the governing party at a by-election since World War Two.
"It's quite a spectacular turnaround in a seat that Labour should really have saved and defended," politics professor Michael Thrasher told Sky News.
Voters on Thursday were also electing local councils and parliaments in Scotland and Wales, gauging support for Britain's two main parties and in Scotland's case, the depth of backing for its leading party's push for independence.
The results of the other contests will be released over several days because COVID-19 restrictions have complicated the counts. Early results indicated the Conservatives had gained seats on English councils, which look after local services.
The Hartlepool result continues a trend set by Johnson in the 2019 parliamentary election when he struck directly at Labour's heartlands, the "Red Wall" areas of northern and central England, to win a commanding majority in parliament.
Labour had tried to manage expectations over the vote, saying that Thursday's elections would always be difficult at a time of the coronavirus pandemic, which has boosted support for the government because of its rapid vaccine rollout.
But the loss is painful for Starmer, who has struggled to increase his appeal to the electorate despite heavy criticism of the Conservative government over its initially sluggish response to the COVID-19 crisis and possible conflicts of interest.
He has accused Johnson and his party of cronyism, questioning the financing of the prime minister's apartment, which an election watchdog is investigating. Johnson says he paid for the refurbishment and followed all the rules.
Starmer has tried to shift his party towards the centre ground after two defeats under the left-wing leadership of Jeremy Corbyn. But the Hartlepool defeat drew immediate criticism from some members of the party's leftist faction.
"Not possible to blame Jeremy Corbyn for this result," said lawmaker Diane Abbott, a Corbyn ally. "Keir Starmer must think again about his strategy."
(Reporting by Elizabeth Piper and William James, additional reporting by Paul Sandle, Alistair Smout and Michael Holden; editing by Michael Holden, Paul Sandle, Toby Chopra and Timothy Heritage) ((firstname.lastname@example.org; +44 207 542 3374; Reuters Messaging: email@example.com))