Editor’s Note: Peter Bergen is CNN’s national security analyst, a vice president at New America, a professor of practice at Arizona State University, and the host of the Audible podcast “In the Room with Peter Bergen” also on Apple and Spotify. The opinions expressed in this commentary are his own. View more opinion at CNN.

CNN — 

Russian President Vladimir Putin made a speech Saturday condemning the mutiny by the Wagner group, comparing the uprising to the events sparked by Russia’s 1917 revolution. Putin claimed that the Russians were stabbed “in the back” by nameless enemies towards the end of World War I, which is why the Russians lost that war and that in turn led to “a civil war” in Russia, he said.

It was a strange but telling comparison for Putin to make. Not for the first time Putin’s account of Russian history was seriously off during his remarks on Saturday, but his invocation of the events surrounding the 1917 revolution shows where his head is at.

Like other Russian leaders through history, he has to be concerned that military defeat, in this case the failure of Russia to conquer the much smaller nation of Ukraine, could prove his undoing.

After all, the Communist regime that Putin served as a KGB officer owed its very existence to the 1917 revolution, which was precipitated by the disastrous leadership of Russian emperor Nicholas II during World War I. (Nicholas II had also helped pave the way for the 1917 revolution by his mistakes during the Russo-Japanese War of 1905, which the Russians lost to the Japanese.)

The Russians were not stabbed in the back during World War I, as Putin suggested during his remarks on Saturday. In fact, they fought a ruinous land war in Europe that was characterized by the extreme incompetence of Nicholas II and his senior leadership. As Russian losses on the battlefield mounted, Russian soldiers mutinied, helping to instigate the 1917 revolution. Sound familiar?

During the 1917 revolution, a Marxist party known as the Bolsheviks seized power. A year later, Nicholas II and other members of the ruling Romanov family ended up on the wrong end of a firing squad. The Bolsheviks then evolved into the Communist Party, the supreme source of power in the Soviet Union until its collapse in 1991.

A keen student of Russian history, Putin is aware of the stakes here. His invocation of the events in 1917 shows that he knows that the Wagner group mutiny may pose an existential threat to his regime. He has expunged pretty much all resistance by any civilian organizations, so he only faces a real threat from Russian military forces.

Arguably no event better explains Putin’s view of the world than the fall of the Berlin Wall in December 1989 when he was a KGB officer posted in Dresden in what was then East Germany. The fall of the wall was a prelude to the implosion of the Soviet Union two years later. Ever since then, Putin has been trying to make Russia great again.

The Russian withdrawal from Afghanistan in February 1989 after an almost decade-long war helped set the stage for both the fall of the Berlin Wall and of the Soviet Union. If the Soviets couldn’t defeat a lightly armed Afghan guerilla force in a country they shared a border with, what did it say about their ability to maintain their iron grip on Eastern Europe?

Military defeats in the Russo-Japanese War and World War I proved fatal for the Romanovs, while defeat in Afghanistan hastened the end of the Soviet empire. By contrast, dictator Josef Stalin’s key role in the defeat of the Nazis during World War II helped to ensure that he died peacefully in his own bed and even today, he remains a popular figure among Russians.

Putin is surely aware that history may not repeat itself but sometimes it can rhyme, to paraphrase a remark often attributed to Mark Twain.

Putin doesn’t want to go the way of the Romanovs nor of the Soviets and would prefer Stalin’s comfortable exit from this world when the time comes. The big question will be: Can he pull it off? And the short answer is that no one knows if he can, including Putin himself.