“Nearly the whole country has emptied out,” she said. “And nearly everyone has made it through.”

Shortly before taking office on June 1, the new president, Nayib Bukele, signaled he had little appetite for grand Chinese ventures despite his promises to create jobs and attract investment.

The Chinese, he said, “go in, do projects that are not feasible, then they leave the countries with huge loans they cannot repay and use that as leverage.”

Weeks after taking power, however, he struck a different note and ruled out the possibility of switching El Salvador’s allegiance back to Taiwan. “We need to recognize China’s status in the world,” he said.

And in the long run, some American officials fear that China’s willingness to build roads, railroads and ports in the region will be impossible for El Salvador and some of its neighbors to resist.

Norma Torres, a Guatemalan-born representative from California who has become a leading voice on Central America policy on Capitol Hill, said the Trump administration’s focus on keeping migrants out will benefit China.

“They are not looking at short-term, immediate results as we do here in the United States,” Ms. Torres said. “The Chinese have focused on, ‘Where are we going to be in the next 20 years?’”

While the port deal was sidetracked, at least for the time being, it is clear the Chinese are positioning to become El Salvador’s ally of choice.

“Under the careful care of each side, the China-El Salvador relationship will, without doubt, transform from a shrub into a verdant tree,” Ms. Ou, China’s ambassador, wrote in a recent opinion piece published in a local newspaper. “The bilateral cooperation will be as fragrant and delicious as Salvadoran coffee and as sweet and tasty as the sugar of this beautiful nation!”