BEIJING — Worried that international travelers might trigger a second wave of coronavirus infections, China announced late Thursday night that it was suspending practically all entry to the country by foreigners and was halting almost all international passenger flights as well.

The announcement came after official Chinese data indicated that the country had almost completely halted domestic transmission of the virus but was struggling to handle a growing number of people who were infected overseas.

Foreign residents of China and foreigners with previously issued visas will no longer be allowed to enter the country as of midnight Friday, China’s foreign ministry declared late Thursday. The announcement represents one of the most comprehensive international travel bans imposed anywhere in the world, as governments try to slow the spread of the coronavirus that has already infected more than a half million people and killed more than 22,000.

Other leaders who have imposed travel bans, including President Trump, have tended to allow long-term residents from other countries to keep coming and going, even as they restricted most other arrivals. President Trump’s travel ban on China on Jan. 31 also exempted immediate family members of American citizens.