Soon after Russia invaded Ukraine, Taiwan’s leaders joined the United States and its allies in declaring solidarity with the victim. Taiwan and Ukraine were fellow democracies, they said, each imperiled by its hulking, authoritarian neighbor.

Now, President Trump’s turn against Ukraine could fan debate in Taiwan about whether it can count on American support in the event of a widening conflict with China, which claims the self-governed island as its territory.

“Taiwan spent the better part of the past three years making the case for how the fate of democracies is intimately tied and what happens to Ukraine affects Taiwan,” said Russell Hsiao, the executive director of the Global Taiwan Institute, which is based in Washington.

“With the seemingly abrupt change in the U.S. position on the Ukraine war,” Mr. Hsiao said, “this could have the effect of causing some in Taiwan to question whether the United States could pull the rug from underneath them.”

For decades, Taiwan has faced the possibility of invasion by China, which now sends fighter jets and warships nearly every day to probe its defenses. Taiwan’s ability to deter a potential attack hinges on whether the United States stands ready to help and even send forces. The island’s leaders have made closer ties with Washington a pillar of its foreign and defense policy for nearly a decade.

But as Mr. Trump executes a dramatic reversal of U.S. policy toward Ukraine, abandoning Western efforts to punish Russia for the invasion and insisting that Ukraine is to blame for the war, the United States’ partners, including Taiwan, are being forced to assess their own positions and weigh how to secure Mr. Trump’s support.

In Taiwan, Mr. Trump’s stinging comments about Ukraine could feed a current of public opinion arguing that the island has been repeatedly abandoned by Washington and cannot trust its promises.

“The prospect of the United States trying to make a deal with Russia over Ukraine, without actually giving Ukraine a seat at the table, will reinforce the sense of American skepticism in Taiwan,” said Marcin Jerzewski, the head of the Taiwan office of the European Values Center for Security Policy, which tries to foster cooperation between European and Asian democracies.

Some anxiety has surfaced on social media, with a few Taiwanese commentators suggesting that if war between China and Taiwan should erupt, Mr. Trump might take a similarly transactional approach. (Taiwanese officials have said that the Chinese government covertly amplifies skeptical online talk about Washington in Taiwan.)

On Sunday, dozens of Ukrainians and Taiwanese gathered outside the de facto Russian embassy in Taipei. “Russia is the aggressor,” one organizer said — a message tacitly, yet pointedly, aimed at Mr. Trump.

“If today he could abandon Ukraine — and I don’t know if he’s really going to abandon Ukraine — then could he also abandon Taiwan?” said Huang Yu-hsiang, a 23-year old technician who was at the protest. “If they don’t care about values, that means they could abandon Taiwan, a consistent supporter of democracy.”

Mr. Trump does not appear to have a strong commitment to Taiwanese democracy. That has contributed to concerns that he might put Taiwan’s interests at risk if he negotiates a big trade deal with China’s leader, Xi Jinping, who has told Mr. Trump and previous American presidents that Taiwan is a key concern in their relationship.

For now, Taiwanese officials have been sounding a positive note about relations with Washington, taking care to avoid an open rift with Mr. Trump. At a security forum in Taipei last week, President Lai Ching-te cast Taiwan as a key player in democracies’ struggle against authoritarian powers like as Russia, China and Iran. But Taiwan’s statements of support for Ukraine have been measured lately, avoiding specifics about Mr. Trump’s decisions.

What does Taiwan think of the possibility that the United States might cut off support for Ukraine or force it to accept peace terms that favor Russia? Joseph Wu, the secretary general of Taiwan’s National Security Council and a former foreign minister, sidestepped the question at the same security forum.

“Serving in the Ministry of Foreign Affairs for six — for more than six — years, I know there are things I can say, and there are things I cannot say,” Mr. Wu said. He emphasized that Taiwan understood that it needed to strengthen its military. “Our own fate is controlled in our hands,” he said.

When President Vladimir V. Putin sent Russian forces rumbling into Ukraine in a full invasion three years ago, Taiwanese leaders had already been worried that Mr. Xi might feel emboldened to try something similar on their soil. He had overseen a harsh security crackdown in Hong Kong and a rapid buildup of China’s military.

Tsai Ing-wen, Taiwan’s president at the time, and her officials drew rhetorical parallels between Taiwan and Ukraine as they sought to raise public support for their policies, including more military preparations and the strengthening of ties with other democracies.

Invaders must not go unpunished, Bi-khim Hsiao, who is now Taiwan’s vice president, told reporters in 2023, when she was its chief representative in Washington. “We must ensure that anyone contemplating the possibility of an invasion understands that,” she said, “and that is why Ukraine’s success in defending against aggression is so important also for Taiwan.”

It was clear to Taiwan that Mr. Trump’s return to the White House would inject uncertainty into the relationship with the United States, even before his recent statements about Ukraine.

As a candidate for the White House and after taking office, Mr. Trump said Taiwan was spending far too little on its military and was too complacent about the United States coming to its rescue in a war. He also accused Taiwan of unfairly gaining dominance in the manufacture of advanced semiconductors for smartphones and other technology.

But Taiwanese officials and experts have said that, pressure from Mr. Trump notwithstanding, Taiwan is very different from Ukraine and more economically important to the United States. They argue that the Trump administration sees China as a more pressing challenge for the United States than Russia, and that Taiwan can be a loyal partner in that context.

Mr. Lai, Taiwan’s president, has been trying to head off any serious breach with Mr. Trump. This month, he announced that Taiwan would increase military spending to at least 3 percent of its economic output (up from about 2.45 percent this year). He also said the island — which has more semiconductor fabrication plants, or “fabs,” than any other place in the world — would come up with proposals in response to Mr. Trump’s demand that more such plants be built in the United States.

“From additional arms purchases and energy imports to semiconductor fabs in the United States, the Lai administration will have to come up with an optimal mix that can catch the attention of President Trump and make haste,” said Mr. Hsiao, the researcher in Washington. “Time is really of the essence for Taipei.”