US President Joe Biden has warned China is "flirting with danger" over Taiwan, and vowed to intervene militarily to protect the island if it is attacked.
Speaking in Japan, he appeared to contradict long-standing US policy in the region, although the White House insisted there had been no departure.
Mr Biden drew a parallel between Taiwan and Russia's invasion of Ukraine, prompting an angry rebuke from Beijing.
He is on his first tour of Asia as US president, visiting regional allies.
Mr Biden prefaced his remarks saying US policy toward Taiwan "has not changed". But his comments in Tokyo are the second time in recent months he has unequivocally stated the US would defend Taiwan if China attacked, in what has been seen as a change in tone.
The US has previously been vague on what it would do in such a situation.
China regards Taiwan as a breakaway province that must be re-unified with the mainland.
Beijing's foreign ministry spokesman Wang Wenbin insisted: "Taiwan is an inalienable part of China's territory... there's no room for compromise or concession.
"The Taiwan question and the Ukraine issue are fundamentally different. To compare those two is absurd. We once again urge the US to abide by the One China principle."
The US has no official diplomatic ties with Taiwan, but sells arms to it as part of its Taiwan Relations Act, which states that the US must provide the island with the means to defend itself.
At the same time, it maintains formal ties with China and also diplomatically acknowledges China's position that there is only one Chinese government.
Mr Biden was answering questions in Tokyo during a press conference with Japanese PM Fumio Kishida, when a journalist asked them about the defence of Taiwan.
The US president began by directly linking the China-Taiwan situation to Russia's invasion of Ukraine. If there was a rapprochement eventually between Ukraine and Russia, and sanctions were not sustained, "then what does this signal to China about the cost of attempting to take Taiwan by force?" he asked.
"They are already flirting with danger right now by flying so close and all the manoeuvres that they are undertaking," Mr Biden said, referring to increasing reports of Chinese warplane incursions into Taiwan's self-declared air defence zone.
He added that while "my expectation is that it [a Chinese invasion] will not happen, it will not be attempted", at the same time it depended on "how strong the world makes clear that that kind of action is going to result in long term disapprobation".
He was then asked directly if the US would defend Taiwan militarily if China invaded, when it has not done so in the invasion of Ukraine, and he responded: "Yes... that's the commitment we made.
"The idea that it can be taken by force... is just not appropriate. It will dislocate the entire region and be another action similar to what happened in Ukraine."
It took the US State Department only minutes to start walking back Joe Biden's comments.
This is not the first time he has said he would defend Taiwan. It could be an expression of his deep personal disquiet about the Ukraine invasion, and the prospect of something similar happening in Taiwan.
In March, he did something very similar when he said "Vladmir Putin cannot stay in power", forcing US officials to swiftly deny America was calling for regime change in Moscow. But when asked about it later, Mr Biden did not back down. He was, he said, expressing his "moral outrage" at what Putin was doing.
Today he seemed to be saying "I won't let that happen to Taiwan". The official position of the US government on Taiwan is "strategic ambiguity" - the US doesn't commit to defend Taiwan, but it doesn't say it wouldn't either. This is supposed to keep China guessing.
But as China has got stronger, and its threats to Taiwan more real, there have been voices calling for an end to this fudge.
Former Japanese PM Shinzo Abe recently said it was time for America to be clear to Beijing - and say it would defend Taiwan. Others think this is a really bad idea and could provoke Beijing in to accelerating its plans to retake the island.
Privately, many senior officials in Washington and Tokyo are extremely worried about Taiwan, about Beijing's growing military advantage, and they are fumbling for a new strategy to deal with the threat.
In the meantime, Mr Biden seems to be speaking his own truth.