LONDON — For days, Prime Minister Boris Johnson charted a defiantly maverick course in Britain’s response to the coronavirus pandemic, refusing to shut down large parts of his country, as many other European leaders have.

On Friday, however, Mr. Johnson finally conceded, announcing that the government had ordered the shutdown of pubs, cafes, restaurants, clubs, gyms and theaters as of midnight in an increasingly anxious bid to curb the virus that has spread to more than 3,000 people.

Mr. Johnson’s reluctant action effectively brought the United Kingdom in line with France and other continental European nations, ending the country’s more relaxed but heavily criticized approach — one that showed how Brexit may encourage it to go its own way on public health and economic policy.

“People have already made a huge effort to comply,” a visibly chagrined Mr. Johnson said as he announced the shutdown at his daily news conference. “But we need now to push down further on that curve.”