But when the coronavirus began spreading through Wuhan, Mr. Evans shut himself inside his apartment, stocked up with rice, noodles, eggs and disinfectant.

“I did exactly what every Chinese person did,” he said.

“I locked myself in. The city turned into a ghost town,” Mr. Evans said. But he felt isolated, he said, and his mother, back in the United States, was worried for his safety.

When he heard of a flight out of the country, he quickly filled out the online forms. An email from the United States Embassy in Beijing arrived, which read: “Space on this flight is extremely limited and we respectfully request that you not share details regarding the flight, including on social media.”

Mr. Evans learned that he was No. 171 on a flight that could accommodate about 200, he said. “I felt very lucky to be chosen out of all U.S. residents in Wuhan,” he said. Some Americans reported that they had tried to get a seat on the flight but were told there was no room.

Mr. McCoy, who lives in Shanghai, was in Wuhan working on a mall he is refashioning into a theme park when he got caught in the lockdown.

The atmosphere in the city was “just short of panic,” he recalled.

A former Marine who has run 12 marathons and stays in good shape, Mr. McCoy said he was convinced he had not contracted the virus. But he still took the outbreak seriously. He decided it was worth plunking down $1,100 for a one-way ticket to the United States.