Australian officials abruptly locked down the city of Perth in Western Australia for five days after one person tested positive there for the coronavirus — a security guard at a quarantine hotel. The state of Western Australia had gone nearly 10 months without any sign of community transmission.

Under the new restrictions, about 2 million people in the city and surrounding areas can leave home only for essential reasons like exercise, medical needs and shopping for groceries until Friday evening. Restaurants, bars and gyms will shut and mask-wearing will be compulsory in public. Schools, which were scheduled to reopen this week, will remain closed.

“I know for many Western Australians, this is going to come as a shock,” Mark McGowan, the state’s premier, said at a news conference announcing the measures Sunday. The state had “crushed” the outbreak before, he said, but “we cannot forget how quickly this virus can spread, nor the devastation it can cause.”

The security guard developed symptoms Thursday after working that week at a hotel where travelers are quarantined, McGowan said. One traveler there had tested positive for the more contagious virus variant that was first spotted in Britain.

Australia has been praised for its comparative success in handling the pandemic, reporting a total of 28,810 cases and 909 deaths, far fewer relative to its size than most other developed countries. It has moved aggressively to clamp down on new outbreaks, and it has largely banned its citizens from leaving the country. New cases have mainly been discovered in returning travelers, who are strictly quarantined in hotels.

The city of Brisbane quickly imposed a three-day lockdown in January after a cleaner who worked at a quarantine hotel there tested positive.

The country has reopened a travel bubble with neighboring New Zealand and has begun to allow domestic travel from state to state, although officials have not hesitated to close state borders against emerging outbreaks.