WASHINGTON — For nine weeks, President Biden and the Western allies have emphasized the need to keep the war for Ukraine inside Ukraine.

Now, the fear in Washington and European capitals is that the conflict may soon escalate into a wider war — spreading to neighboring states, to cyberspace and to NATO countries suddenly facing a Russian cutoff of gas. Over the long term, such an expansion could evolve into a more direct conflict between Washington and Moscow reminiscent of the Cold War, as each seeks to sap the other’s power.

In the past three days, the American secretary of defense has called for an effort to degrade the capability of the Russian military so that it could not invade another country for years to come. The Russians have cut off gas shipments to Poland and Bulgaria, which joined the North Atlantic Treaty Organization after the collapse of the Soviet Union; Ursula von der Leyen, the president of the European Commission, immediately denounced the move as an “instrument of blackmail.” Explosions have rocked a disputed area of Moldova, a natural next target for the Russians, and gas depots and even a missile factory in Russia have mysteriously caught fire or come under direct attack from Ukrainian forces.

And with increasing frequency, the Russians are reminding the world of the size and power of their nuclear arsenal, an unsubtle warning that if President Vladimir V. Putin’s conventional forces face any more humiliating losses, he has other options. American and European officials say they see no evidence the Russians are mobilizing their battlefield nuclear forces, but behind the scenes, the officials are already gaming out how they might react to a Russian nuclear test, or demonstration explosion, over the Black Sea or on Ukrainian territory.

“Nobody wants to see this war escalate any more than it already has,” John Kirby, the Pentagon spokesman, said on Wednesday when asked about Russia’s nuclear threats. “Certainly nobody wants to see, or nobody should want to see, it escalate into the nuclear realm.”

American and European officials say their fears are based in part on the growing conviction that the conflict could “go on for some time,” as Secretary of State Antony J. Blinken put it recently.

Talk of a diplomatic resolution or even a cease-fire — attempted at various points by the leaders of France, Israel and Turkey, among others — has died out. Both Ukrainian and Russian forces are digging in for the long haul, focusing on what they expect will be an artillery war in the south and east of the country, where Russia has focused its forces after a humiliating retreat from Kyiv and other key cities.

“Putin is not willing to back down, nor are the Ukrainians, so there is more blood to come,” said Robin Niblett, the director of Chatham House, a British think tank. At the same time, American and European determination to help Ukraine defeat the Russians has hardened, partly after the atrocities in Bucha and other towns occupied by the Russians became clear, with even Germany overcoming its initial objections and sending artillery and armored vehicles.

Seth G. Jones, who directs the European Security Program at the Center for Strategic and International Studies in Washington, said on Wednesday that “the risk of a widening war is serious right now.”

“Russian casualties are continuing to mount, and the U.S. is committed to shipping more powerful weapons that are causing those casualties,” Mr. Jones said. Sooner or later, he added, Russia’s military intelligence service might begin to target those weapons shipments inside NATO’s borders.

Credit…Finbarr O’Reilly for The New York Times

Not all lines of communication between Washington and Moscow have collapsed. The U.S. and Russia announced a prisoner swap early on Wednesday. The exchange took place secretly in Turkey, where Trevor Reed, a former Marine, was swapped for a Russian pilot whom the Justice Department had long called “an experienced international drug trafficker.” But even that had a return-to-the-Cold-War air about it, highlighting how much of the current conflict is also a power struggle between Washington and Moscow.

The moment seemed to reinforce the argument that Stephen Kotkin, a professor at Princeton University and senior fellow at the Hoover Institution at Stanford, made in Foreign Affairs recently when he wrote that “the original Cold War’s end was a mirage,” as the effort to integrate Russia into the West slowly collapsed.

Mr. Biden himself has endorsed the theory that Mr. Putin has designs that go beyond Ukraine. The invasion, he said on the day it began, Feb. 24, was “always about naked aggression, about Putin’s desire for empire by any means necessary.”

But so far, the war has stayed largely within the geographical confines of Ukraine. The United States and its allies said their goal was to get Russia to withdraw its forces “irreversibly,” as Mr. Blinken put it, and respect Ukraine’s borders as they existed before the invasion. Mr. Biden declined to impose an no-fly zone that would pit American and Russian pilots against each other. Mr. Putin denounced the influx of Western weapons to help the Ukrainian military, but has never attacked those supply lines inside NATO territory.

Now, there are signs that the restraint is fracturing.

When Gazprom, the Russian energy giant, cut off the flow to Poland and Bulgaria, it was clearly a warning sign that Germany — hugely dependent on Russian gas — could be next. Russia was using its most potent economic weapon, sending a message that it could bring pain and, next winter, considerable cold to Eastern and Western Europe without firing a shot. American officials said it was clearly an effort to fragment the NATO allies, who have so far remained united.

Coincidentally or not, Mr. Putin’s move came just after Defense Secretary Lloyd J. Austin III went beyond the administration’s oft-repeated statement that it wanted to make sure Russia emerged from its Ukraine experience strategically weakened.

Credit…Lynsey Addario for The New York Times

“We want to see Russia weakened to the degree that it can’t do the kinds of things that it has done in invading Ukraine,” Mr. Austin said, a line that seemed to suggest the U.S. wanted to erode Russian military power for years — presumably as long as Mr. Putin remains in power. The export controls the U.S. has imposed on key microelectronic components Russia needs to produce its missiles and tanks appear designed to do just that.

Some Europeans wondered whether Washington’s war aims had broadened from helping Ukraine to defend itself, which has broad support, to damaging Russia itself, a controversial goal that would feed into a Russian narrative that Moscow’s actions in Ukraine are to defend itself against NATO.

Some administration officials insist Mr. Austin’s comments were overinterpreted, and that he was not suggesting a long-term strategic goal of undermining Russian power. Instead, they say, he was just amplifying past statements about the need to sharpen the choices facing Mr. Putin — while setting back Russia’s ability to launch another invasion once it regroups.

But many in Europe thought his statement suggested a long war of attrition that could have many fronts.

“Are we headed for a wider war or is this just a gaffe by Austin?” asked François Heisbourg, a French defense analyst.

“There is a widening consensus about supplying Ukraine howitzers and more complex weapons systems, and everyone is now doing that,” Mr. Heisbourg noted.

“But it’s another thing to pivot the war aim from Ukraine to Russia. I don’t believe there’s any consensus on that.” Weakening Russia’s military capacity “is a good thing to do,” Mr. Heisbourg said, “but it’s a means to an end, not an end in itself.”

There are other factors that risk broadening the conflict. Within weeks, Sweden and Finland are expected to seek entry into NATO — expanding the alliance in reaction to Mr. Putin’s efforts to break it up. But the process could take months because each NATO country would have to ratify the move, and that could open a period of vulnerability. Russia could threaten both countries before they are formally accepted into the alliance and are covered by the NATO treaty that stipulates an attack on one member is an attack on all.

But there is less and less doubt that Sweden and Finland will become the 31st and 32nd members of the alliance. Mr. Niblett said a new expansion of NATO — just what Mr. Putin has been objecting to for the last two decades — would “make explicit the new front lines of the standoff with Russia.”

Not surprisingly, both sides are playing on the fear that the war could spread, in propaganda campaigns that parallel the ongoing war on the ground. President Volodymyr Zelensky of Ukraine frequently raises the possibility in his evening radio addresses; two weeks ago, imploring NATO allies for more arms, he argued that “we can either stop Russia or lose the whole of Eastern Europe.”

Russia has its own handbook, episodically arguing that its goals go beyond “denazification” of Ukraine to the removal of NATO forces and weapons from allied countries that did not host either before 1997. Moscow’s frequent references to the growing risk of nuclear war seem intended to drive home the point that the West should not push too far.

That message resonates in Germany, which has long sought to avoid provoking Mr. Putin, said Ulrich Speck, a German analyst. To say that “Russia must not win,” he said, is different from saying “Russia must lose.”

There is a concern in Berlin that “we shouldn’t push Putin too hard against the wall,” Mr. Speck said, “so that he may become desperate and do something truly irresponsible.”