DANANG, Vietnam -- Hours after leaving Beijing, President Trump delivered what appeared to be a sharp rebuke to China Friday, declaring he won't allow the U.S. 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, Mr. 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.

Get Breaking News Delivered to Your Inbox

Mr. Trump said the U.S. would make a deal with any country in the Indo-Pacific region, but only one with "mutual respect and mutual benefit."

Even though he was addressing a meeting at the summit of Asia-Pacific nations, he kept using the term "Indo-Pacific," and brought up how important India is.

It was a striking change of tone from the day before, when Mr. 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.

President Trump speaking to CEOs at Asia-Pacific Economic Cooperation (APEC) summit, in Danang, Vietnam, on November 10, 2017 POOL / REUTERS

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

Mr. 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, Mr. Trump said, "I give China great credit."

Chinese President Xi Jinping said Friday nations need to stay committed to economic openness or risk being "left behind."

Xi made the remarks in a speech to a business conference in Danang. He spoke shortly after Mr. Trump did.

The Chinese president urged support for the "multilateral trading regime" and progress toward a free-trade zone in the Asia-Pacific, drawing loud applause. He said that "self-seclusion leaves one behind."

Mr. Trump also said Friday the whole world was being lifted by America's economic renewal, and that a "new optimism" has swept across the U.S. since his election.

Mr. 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.

On North Korea, Mr. Trump said the region must not be held hostage to a dictator's "twisted fantasies of violent conquest and nuclear blackmail." He was referring to North Korean leader Kim Jong Un.

Mr. Trump referenced his address in South Korea earlier this week when he called on countries to unite against Pyongyang. He said "every single step the North Korea regime takes toward more weapons is a step it takes into greater and greater danger."

Mr. Trump also says civilized people must "come together" to drive out terrorists and extremists from our societies.

He was speaking shortly after arriving in this coastal city for the summit after a flight from Beijing as he continued his Asia tour.