Not to be outdone, Senator Bernie Sanders of Vermont said that he would stop giving military contracts to companies that did not employ American workers to manufacture their products.

“If anybody here thinks that corporate America gives one damn about the average American worker, you’re mistaken,” said Mr. Sanders, a self-described democratic socialist. “If they can save 5 cents to Mexico or China or Vietnam, that’s what they’ll do.”

Republican and Democratic positions on trade have gyrated in recent years as Mr. Trump has employed tariffs, with limited success, as a tool for rebalancing America’s trade relationships. It was less than four years ago that President Barack Obama concluded years of negotiations with Pacific Rim nations to join the Trans-Pacific Partnership, a trade pact widely seen as countering China’s rising economic dominance in the region. But the deal floundered in Congress and was shunned in 2016 by Mr. Sanders and Hillary Clinton, the leading Democratic candidates that year, as Mr. Trump began to outflank them on trade.

This year, nearly all the leading Democratic contenders have embraced a get-tough approach to China. Even Mr. Delaney, the most pro-trade candidate in Tuesday’s debate, framed his support for the Pacific trade deal in part as an effort to contain China. And on a night when kind words for Mr. Trump were rare, Representative Tim Ryan of Ohio acknowledged some alignment with the president’s China policies.

“Look, I think President Trump was onto something when he talked about China,” Mr. Ryan said. “China has been abusing the economic system for a long time.”