As the second anniversary of Russia’s invasion of Ukraine approaches, it has become a commonplace that time favors President Vladimir Putin. With Ukraine running low on weaponry and ammunition, American military assistance in doubt and Russia determined to fight on, Ukrainian victory now seems out of reach. Some influential experts go further, insisting that Kyiv will suffer only more death and destruction by persisting and should seek a political settlement with Moscow — even if it requires sacrificing territory.

And yet, for all that, Mr. Putin’s war has failed. As Carl von Clausewitz famously stressed, war is not ultimately about killing people and destroying things: It’s a means to achieve specific political ends. Those who start wars expect to be in a better strategic position once the gunfire stops. But even if this war ends with Russia retaining all the Ukrainian land it now holds — a scenario Ukrainians would find more than unpalatable — Moscow’s position will be worse. No matter what, Ukraine will go its own way. For Mr. Putin, more concerned by Ukraine than any other country that arose from the wreckage of the Soviet Union, that alone is tantamount to defeat.

If the fundamental purpose of Mr. Putin’s war was to keep Ukraine within Russia’s orbit — politically, culturally and economically — it has had the opposite effect. Ukraine’s leaders and citizens, particularly those from younger generations, have decided that their future lies with the West, not Russia. The prevalence of this mind-set became increasingly palpable over the course of four trips I have taken to Ukraine since the invasion; no visitor to Ukraine will fail to be struck by its many daily manifestations. Everywhere you go, Ukrainians speak Western languages, particularly English, in seemingly ever greater numbers.

Ukraine tends to be depicted as an uneasy amalgam of two national communities: one in the country’s western regions, defined by Ukrainian ethnicity and language, the other in its Russophone east and south. If this was ever wholly accurate, it is no longer. To take one example, any visitor to Ukraine’s eastern and southern front lines will encounter soldiers who speak to one another in Russian and may not even know Ukrainian. But they see themselves as citizens of Ukraine committed to preventing Russia from subordinating their homeland — a cause for which they are prepared to die.

More than any other event, Russia’s full-scale invasion in 2022 has contributed to this sentiment. Ukrainian nationalism today, transcending region and language, reflects a deep determination to forge an identity defined by separation from, even antipathy toward, Russia. Indeed, Mr. Putin may go down in history as one of its main, if unwitting, catalysts. Given his conviction that Russians and Ukrainians are really one people, such a result is especially ironic.

His war has backfired not only in Ukraine but also in Europe. The European Union, jolted into action by the invasion, summoned a common spirit in its support for Ukraine. Previously somewhat divided in its approach to Russia, the bloc has acted in near unanimity — Prime Minister Viktor Orban of Hungary being the only exception — to oppose Mr. Putin’s act of aggression. Equally important, Ukraine’s journey toward E.U. membership, for years fiercely opposed in Moscow, is now very much in train, even if it won’t be a short ride. One sign of progress: Along with Moldova, Ukraine officially began negotiations to join the bloc late last year.