There is a growing confidence in the western alliance about the course of the war in Ukraine. That confidence is both justified and potentially dangerous.

The invasion has gone far worse for Russia than most people dared hope in the west. The western allies have surprised even themselves with the strength, speed and unity of their response — with unprecedented sanctions imposed on Russia and military aid poured into Ukraine.

The increasingly bullish mood in Washington and parts of Europe was reflected in Joe Biden’s controversial remark that Russia’s Vladimir Putin “cannot remain in power”. The US president is widely assumed to have spoken in an ill-considered way that his aides had to swiftly walk back. But his comments reflect a sense in Washington that some form of “regime change” in Russia is both conceivable and desirable.

Putin’s domestic and international position does indeed look more perilous than before the invasion. But the less-discussed reality is that the war also poses big and growing political risks for the governments of the west.

The danger is that Russia manages to continue the fight for many months — with a growing toll in death and destruction. Meanwhile, the effects of the economic rupture with Moscow will begin to be felt much more acutely in Europe in the form of rising prices, energy shortages, lost jobs and the social impact of trying to absorb as many as 10mn Ukrainian refugees.

America is less economically exposed than Europe. But the war started with US inflation already high and Biden’s popularity ratings low. Petrol prices are now soaring and that always goes down badly with American voters.

Energy bills for consumers and businesses in Europe were also rising sharply even before the war. Now they are set to soar. In the UK, households could see a 50 per cent increase in energy bills in April, followed by another 50 per cent rise in October.

The EU’s target of reducing dependence on Russian gas by two-thirds by the end of the year is decried by some as too weak a response, since it means that Russia continues to receive billions of euros a week in income from exports. But, at the FT commodities conference last week, traders warned that even that reduction in purchases will be very hard to achieve. Some believe that a shortage of diesel from Russia could lead to fuel rationing in Europe this year.

Food prices are also likely to soar, reflecting the importance of Ukraine and Russia to the global wheat and fertiliser markets. As a result, the number of Europeans using food banks or requiring emergency assistance will increase.

In the Middle East, meanwhile, where governments have fewer resources to cushion the impact of food-price rises, there could be a sharp increase in hunger. That, in turn, might lead to a new surge of desperate people trying to leave for Europe. Governments in Europe, already struggling to cope with millions of Ukrainians, could soon be dealing with many more would-be migrants from the Middle East and Africa.

The public response to these developments in Europe and the US is likely to be volatile and contradictory. The current focus on Ukraine in the media will probably wane, as the war loses its shock value. By the autumn, the economic crisis could dominate politics. That would provide fertile ground for a resurgence of populists such as Donald Trump in the US, Marine Le Pen in France or Matteo Salvini in Italy — all of whom have been noted Putin fans in the past.

Of course, the economic pressure on Russia will be much more intense. But Putin runs a dictatorship. Leaders of western democracies have to worry about their voters. They know that, historically, few governments can survive stagflation and the accompanying cost-of-living crisis.

As the economic pressure mounts, so western unity could fracture — leading to contradictory pressures on political leaders. More outrages in Ukraine, such as the destruction of Mariupol, will lead to demands for an even tougher western response — up to and including direct military intervention in the conflict.

At the same time, there will be a resurgence of the “Putin understanders”: a faction of western (particularly German) opinion that has for the moment fallen largely silent. They will demand an end to the conflict, even if that means withdrawing support for Ukraine and making concessions to Russia that currently seem unacceptable.

That tension is already beginning to emerge among western governments. Emmanuel Macron, France’s president, has implicitly reprimanded Biden by urging western leaders to avoid escalatory rhetoric that makes it impossible to achieve a peace settlement in Ukraine.

But Macron may be investing too much hope in the prospects for peace negotiations. Despite the current headlines about peace talks in Turkey, the two sides remain far apart. There is little real evidence that Putin is yet prepared to accept anything short of the victory he has promised Russia.

A long war will increase the political and economic pressure on western governments. Biden’s demand for Putin to go may have been undiplomatic, but he is surely right to suggest that normal relations between Russia and the west are inconceivable while Putin remains in power. Regime change in Russia may be necessary to avoid political turmoil in the west.