DANANG, Vietnam — Hours after leaving Beijing, President Donald Trump on Friday delivered what appeared to be a sharp rebuke to China, declaring that he won’t allow the US to be “taken advantage of anymore” when it comes to trade. He pledged to always “put America first.”

Speaking at a gathering of CEOs at the Asia-Pacific Economic Cooperation summit in Vietnam, Trump said: “From this day forward, we will compete on a fair and equal basis.”

“We are not going to let the United States be taken advantage of anymore. I am always going to put America first,” he said.

It was a striking change of tone from the day before, when Trump set aside his previous blistering rhetoric in favor of friendly overtures to China as he sought to flatter his host into establishing a more balanced trade relationship, rather than lecturing.

In Beijing, Trump criticized the “very one-sided and unfair” relationship between the US and China. But unlike his approach during the presidential campaign, when he castigated China for what he contended were inappropriate trade practices, Trump said Thursday he didn’t blame the Chinese for having taken advantage of the US in the past.

Trump said China “must immediately address the unfair trade practices” that drive a “shockingly” large trade deficit, along with barriers to market access, forced technology transfers and intellectual property theft.

“But I don’t blame China,” he said. “After all, who can blame a country for being able to take advantage of another country for the benefit of its citizens?”

To applause, Trump said, “I give China great credit.”

Trump also said Friday the whole world was being lifted by America’s economic renewal, and that a “new optimism” has swept across the US since his election.

Trump said he’d had the pleasure of sharing the “good news from America” everywhere he’s been on his first official visit to Asia.

“The whole world is lifted by America’s renewal,” he said.