LONDON — For weeks, Prime Minister Boris Johnson of Britain was a defiant holdout among Western leaders in refusing to lock down his country against the spread of the coronavirus. On Friday, he became the first of those leaders known to have contracted the disease.

Mr. Johnson’s diagnosis, confirmed in a test on Thursday, threatened to throw an already rattled British government into turmoil. Fears of a wider contagion grew, as two other senior officials disclosed that they, too, were infected.

And with the heir to the throne, Prince Charles, saying this week that he had fallen ill with the virus, Britain faced the alarming prospect of having to confront its greatest crisis since World War II with several of its leading figures in quarantine.

Mr. Johnson, 55, insisted he would not relinquish his duties. In a remarkable two-minute video posted on Twitter, he used his own case as a sort of teachable moment for the country, appealing to people to work from home and comply with the more drastic social distancing measures he put in place Monday.