Russian President Vladimir Putin attacked Ukraine in February expecting an easy victory.
Instead, Russia's failing war effort has raised doubts about Putin's hold on power.
For now, Putin looks secure, but past Russian leaders have suffered at home for blunders abroad.
Vladimir Putin expected an easy victory in Ukraine, but he has ended up with a fiasco.
Over and over again, demoralized and ill-equipped Russian soldiers have raped, tortured, and looted their way through Ukrainian towns before fleeing in disgrace - often with highly motivated Ukrainian troops close behind them.
In the greatest humiliation yet, Russian forces withdrew from Kherson - the only regional capital that they had captured - just weeks after Putin declared at a triumphant rally on Red Square that the city was "Russian forever."
For now, Putin's rule appears secure. But the experience of past Russian leaders shows how failure at the front can lead to a critical loss of authority at home - sometimes with deadly consequences.
Tsar Nicholas II
The most extreme scenario is the fate of Tsar Nicholas II.
At the outbreak of World War I, Russia had the largest army in Europe. Over 5 million men - 15% of the population - were mobilized in 1914 alone.
But the autocracy's weak infrastructure, transportation links, and low productivity impaired the war effort: Ammunition ran out by the end of 1914. By the following summer, the Germans had taken huge swathes of Russian-controlled territory and a million Russian soldiers were dead.
The Romanov dynasty's out-of-touch scion - a gentle man who preferred gardening and taking photographs with his family to governing - attempted to improve the situation by taking command of the armed forces himself.
While Russia struggled at the front, food shortages and spiraling inflation created chaos back home. When strikes and street protests broke out in Petrograd (now called St. Petersburg) in February 1917, mutinous soldiers joined the riots.
The tsar, forsaken by his generals and advisors, abdicated on a railroad siding in Pskov in March 1917 and was placed under house arrest with his family a few weeks later.
After the Bolsheviks seized control later that year, Vladimir Lenin signed a separate armistice with Germany.
The tsar and his family were shot and stabbed with bayonets by Bolshevik troops in a Yekaterinburg basement in July 1918, bringing the Romanovs' 300-year reign to an ignominious end.
Soviet leader Nikita Khrushchev was also felled in part by a foreign-policy blunder, though it thankfully resulted in no deaths.
In October 1962, an American U-2 spy plane photographed Soviet nuclear missile sites in Cuba. The resulting confrontation between the US and the Soviet Union put the world on the brink of destruction.
But as Secretary of State Dean Rusk put it, "We've been eyeball to eyeball, and someone just blinked." Soviet ships stopped in the water, and Khrushchev announced that the missiles would be removed.
This international embarrassment weakened Khrushchev's position in the leadership.
He could have stepped down with dignity after his 70th birthday in April 1964, but instead he was forced into retirement later that year by a group of rivals who had the support of the KGB.
Ironically, Khrushchev's removal was made possible by his own desire to reject Stalin's despotism. After leading a limited attempt to democratize the Soviet Union, Khrushchev saw his peaceful overthrow as a sign of his success.
He spent the final years of his life in obscurity, dictating his memoirs outside Moscow.
The last and most ambitious Soviet reformer, Mikhail Gorbachev, presided over a military failure that imperiled his authority - and brought the Soviet Union down with it.
When Gorbachev came into office in 1985, he inherited the Soviet Union's flailing war in Afghanistan, launched in 1979 under the sclerotic Leonid Brezhnev. After an ineffectual troop surge, Gorbachev gave up on trying to improve the situation, and the last Soviet troops left Afghanistan in February 1989.
The withdrawal signaled to Eastern Bloc countries that Gorbachev was unwilling to use force to preserve the Soviet empire. In 1989, the Berlin Wall crumbled, Poland held free elections, and sovereignty movements arose within Soviet republics-all without any crackdown from Moscow.
Senior military officers viewed Gorbachev as a traitor and tried to overthrow him in August 1991. After the hardliners failed to seize power, the country fell apart.
In December 1991, Gorbachev's rival, Russian leader Boris Yeltsin, presided over the Soviet Union's dissolution at the Belavezha Accords. But Yeltsin soon began a battle against separatism within Russia that nearly unseated him.
Chechnya, a small Muslim republic in the north Caucasus, declared its independence during the Soviet unraveling and refused to sign a union treaty with the Russian Federation.
One of Yeltsin's advisors thought that "a small victorious war" would boost his approval ratings. In late 1994, he decided to invade.
Yeltsin's team was confident that Chechnya would fall with little resistance. Instead, they found themselves in a guerrilla war against a people eager to overthrow their historical oppressor. After a crushing initial defeat, Russian forces engaged in indiscriminate bombings of cities and towns and brutal retaliation against civilians.
Yeltsin's popularity, already suffering amid an economic crisis, plummeted even further as the devastation in Chechnya was aired on TV. He was reelected in 1996 only with the help of widely reported fraud - and assistance from American campaign advisors who were eager to keep Communists from retaking power.
At least 80,000 people died in the First Chechen War, including tens of thousands of civilians, before Yeltsin signed a peace treaty in May 1997.
When Yeltsin appointed the little-known FSB chief Vladimir Putin as prime minister in August 1999, Putin immediately took up the cause of avenging Russia's humiliation.
Putin declared that his "historical mission" was to "bang the hell out of those bandits." By the end of his first month in office, he had renewed bombing in Chechnya.
This time, Russia's assault was much more popular-and effective. After being elected president, Putin donned a flight suit to celebrate Russian victory in Grozny, the republic's decimated capital, in March 2000.
In his current "historical mission" to reassert Moscow's control over Ukraine, Putin expected to repeat his rapid success in the Second Chechen War. Instead, like Yeltsin in 1994, he encountered a populace united against an existential threat.
In comparison to past leaders who faced foreign-policy failures, Putin's position currently appears relatively stable. He certainly won't be threatened at the ballot box: His United Russia party already engages in massive electoral fraud.
The recent "partial mobilization" of several hundred thousand men has swept up more people than the 120,000 Soviet troops deployed in Afghanistan at the peak of that war but is still far less than the millions sent to the front during World War I.
While hundreds of thousands of Russians have fled abroad to escape the draft, resistance among conscripts has been limited to isolated incidents of violence at conscription centers and training camps. A new law that makes refusing military service or desertion punishable by up to 10 years in prison has helped ensure compliance.
Kremlin spin doctors blame NATO for arming Ukraine and declare that any setbacks are temporary. With the crime of "discrediting the Russian armed forces" punishable by up to 15 years of jail time, most Russians who oppose the war either keep quiet or emigrate.
Though conditions may change under the continuing impact of Western sanctions, Russia has yet to experience the severe economic turmoil that radicalized the masses during World War I.
Putin has tolerated criticism of the war's failures from hawks like the oligarch Yevgeny Prigozhin, who do not target him personally. The mix of forces on the ground - including Prigozhin's Wagner Group mercenaries, Ramzan Kadyrov's Chechen battalions, and regular Russian troops - allows Putin to keep his distance from and deflect personal responsibility for Russia's losses.
It's possible that Putin could be overthrown by disgruntled generals, several of whom have been fired since February. But Russia's prior experience - from the crushed Decembrist uprising against Tsar Nicholas I in 1825 to the drunken August putsch against Gorbachev - suggests that a military takeover would be unlikely to succeed.
In the event of a palace coup, Putin, unlike Khrushchev, wouldn't leave willingly, putting any plotters at enormous risk. However, Putin's grip on power is still far from assured. As more soldiers die, the economy worsens, and discontent festers, the situation in Russia could become combustible.
Nicholas II's downfall shows how the seemingly impossible can suddenly appear inevitable. At the turn of the 20th century, Russia's last tsar was worshiped as a divinely sanctioned autocrat. But when a disastrous war exposed the depths of the Russian empire's dysfunction, he lost support among most of the population and even his closest allies.
Today, Putin's invasion of Ukraine has also revealed crippling problems: ubiquitous corruption that leaves troops without helmets and tanks without fuel; stagnant wages and a low standard of living that lead soldiers to steal everything from canned food to dishwashers; a cynical detachment from politics that dampens protest but also lowers morale; the accumulation of enormous wealth by tycoons who steal resources but do not contribute to effective governance.
Russia's current system is autocratic, but it is also increasingly brittle. Who will be left to defend Putin if his war continues to fail?
Joy Neumeyer is a journalist and historian of Russia and Eastern Europe.