Well before Yevgeny V. Prigozhin seized a major Russian military hub and ordered an armed march on Moscow, posing a startling and dramatic threat to President Vladimir V. Putin, the caterer-turned-mercenary boss was losing his own personal war.

Mr. Prigozhin’s private army had been sidelined. His lucrative government catering contracts had come under threat. The commander he most admired in the Russian military had been removed as the top general overseeing Ukraine. And he had lost his most vital recruiting source for fighters: Russia’s prisons.

Then, on June 13, his only hope for a last-minute intervention to spare him a bitter defeat in his long-running power struggle with Defense Minister Sergei K. Shoigu was dashed.

Mr. Putin sided publicly with Mr. Prigozhin’s adversaries, affirming that all irregular units fighting in Ukraine would have to sign contracts with the Ministry of Defense. That included Mr. Prigozhin’s private military company, Wagner.

Now, the mercenary chieftain would be subordinated to Mr. Shoigu, an unparalleled political survivor in modern Russia and Mr. Prigozhin’s sworn enemy.

“This must be done,” Mr. Putin told a gathering of government-friendly war correspondents at the Kremlin. “It must be done as soon as possible.”

What happened next stunned the world: Mr. Prigozhin mounted an armed insurrection that he insisted was aimed not at deposing Mr. Putin but at overthrowing the Kremlin’s military leadership.

The mutiny, however short-lived, has been widely viewed as an ominous political harbinger for Mr. Putin’s leadership, one that could presage more instability as the Russian president presses on with his costly war.

But it is equally the personal story of an obstreperous and mercurial freelance warlord who undertook an emotional last-ditch attempt to win by force one of the most extraordinary Russian power struggles in recent memory.

Many powerful Russian figures have come out on the losing end of factional battles during Mr. Putin’s 23 years as Russia’s leader, ultimately receding into exile, prison or anonymity.

But with his rebellion over the weekend, Mr. Prigozhin chose a different path, allowing his anguish and anger to play out for the world to see as he took actions uniquely available to someone with a national megaphone — and a well-armed, aggrieved private army.

“Prigozhin’s rebellion wasn’t a bid for power or an attempt to overtake the Kremlin,” Tatyana Stanovaya, a senior fellow at the Carnegie Russia Eurasia Center, wrote in an analysis of the events. “It arose from a sense of desperation; Prigozhin was forced out of Ukraine and found himself unable to sustain Wagner the way he did before, while the state machinery was turning against him.’’

“To top it off,’’ she added, “Putin was ignoring him and publicly supporting his most dangerous adversaries.”

Mr. Prigozhin had built a sizable financial and military empire. But as his political defiance grew, the flow of money from the Defense Ministry and other government contracts was at risk of drying up. And he chafed at the prospect of taking orders from people whom he considered incompetent.

Still, when Mr. Putin denounced his actions on Saturday as treason, Mr. Prigozhin appeared to have been caught off-guard, unprepared to be a true revolutionary or continue a march on the Kremlin that he realized would almost certainly end in defeat, Ms. Stanovaya wrote.

And so when Mr. Prigozhin was offered a chance to end the crisis by withdrawing his forces, he took it.

“Prigozhin’s mutiny was ultimately a desperate act of someone who was cornered,” said Michael Kofman, director of Russia studies at the Virginia-based research group CNA. “His options were narrowing as his bitter dispute intensified.”

Over the years, with his connections to Mr. Putin and the Kremlin, Mr. Prigozhin was able to secure lucrative contracts to provide food for the Moscow school system and Russian military bases, amassing great wealth. At the same time, he engaged in foreign adventurism through Wagner that suited the Kremlin, advancing Moscow’s aims — and his own — in the Middle East and Africa, where his fighters have been accused of indiscriminate killings and atrocities.

He also shepherded the Internet Research Agency, the infamous St. Petersburg troll farm that interfered in the 2016 U.S. presidential election.

So secretive was Mr. Prigozhin about his activities that he long denied any association with Wagner and even sued Russian media outlets for reporting on his connection to the group.

All that changed last year with the full-scale invasion of Ukraine.

In September, Mr. Prigozhin went public for the first time as the man behind Wagner.

Less than two weeks later, Mr. Putin appointed Gen. Sergei Surovikin to lead the war effort in Ukraine, a boon for the mercenary chief, who had worked with the general in Syria. Mr. Prigozhin described the new leader as a legendary figure and the most capable commander in the Russian army.

Mr. Prigozhin’s own stature was growing, too, as his fighters appeared to be making progress in the drawn-out battle for the Ukrainian city of Bakhmut, while the Russian military had little to show. Russian commentators lavished positive coverage upon the mercenary group, and a glass tower in St. Petersburg was rebranded Wagner Center. Recruitment posters for the outfit went up across the country.

But by the beginning of this year, Mr. Prigozhin’s adversaries in the Ministry of Defense began reasserting their power.

In January, Mr. Putin appointed Gen. Valery V. Gerasimov, to replace General Surovikin as the top commander of operations in Ukraine. Mr. Prigozhin frequently belittled General Gerasimov in his Telegram audio messages, implying that he was an office-bound official of the kind that smothers regular soldiers with bureaucracy.

The enmity appears to date at least to Moscow’s intervention in Syria’s civil war, when Wagner and regular Russian soldiers sometimes clashed as they competed for resources and the spoils of war, according to the published memoirs of two Wagner veterans. Mr. Prigozhin himself went public about these tensions in Syria last year.

In February, Mr. Prigozhin acknowledged that his access to Russian prisons to recruit had been cut off. The Defense Ministry would later begin recruiting prisoners there itself, adopting Mr. Prigozhin’s tactic.

Tension between Wagner and the Russian military — long alluded to by Russian military bloggers — exploded into the open. By the end of February, Mr. Prigozhin was publicly accusing Mr. Shoigu and General Gerasimov of treason, claiming that they were deliberately withholding ammunition and supplies from Wagner to destroy it.

At the end of February, Mr. Putin tried to settle the feud by calling Mr. Prigozhin and Mr. Shoigu into a meeting, according to leaked intelligence documents.

But the rivalry would only escalate. No longer able to recruit prisoners, Wagner was forced to rely increasingly on its limited supply of skilled veteran fighters to continue waging battle in Bakhmut, according to Ukrainian and Western officials.

Isolated from the Moscow power center, Mr. Prigozhin increasingly turned to his bully pulpit: social media. His messages also grew far more political as he began appealing directly to the Russian people. He began voicing criticisms that, in a country with a law against discrediting the armed forces, few others dared make.

What had once been sharp-tongued trolling of the Russian brass over time turned into regular eruptions of bile.

“You stinking beasts, what are you doing? You swine!” he said in one recording in late May. “Get your asses out of your offices, which you were given to protect this country.’’

He went on to lambast the Russian defense leadership for “sitting on their big asses smeared with expensive creams” and to say the Russian people had every right to ask questions of them. He posted gruesome images of Wagner soldiers killed in action. He gave ultimatums about pulling his troops out of Bakhmut. He even took what was widely viewed as a swipe at Mr. Putin, without naming him, with a reference to a “grandpa’’ who might be “a complete jackass.”

Kremlinologists were puzzled as to why Mr. Putin did not just sweep the Wagner chief aside, or intervene and rein him in; some analysts suggested that he favored competing factions operating underneath him, with none gaining too much power. Others wondered if the Russian leader had become too isolated to solve the problem or simply did not have sufficient control.

Mr. Prigozhin’s forces captured Bakhmut at the end of May and soon after departed the battlefield, accusing the Russian military of mining the road they used to leave and briefly apprehending a Russian lieutenant colonel on the way out. That left Mr. Prigozhin newly vulnerable. Wagner was no longer needed to finish off a battle that had been played up by the Russian media.

By June, his isolation became palpable.

Mr. Prigozhin signaled a rift with the Ministry of Defense over his military catering contracts, which have helped fuel his wealth and influence for more than a decade. In a publicized letter to Mr. Shoigu dated June 6, Mr. Prigozhin said the food he had supplied to Russian military bases and institutions since 2006 had amounted to a total of 147 billion rubles — $1.74 billion — a figure that is impossible to verify. Now, he complained, “high-level people” were trying to force him to accept companies associated with them as his suppliers. He also said a new system of “loyal suppliers” threatened his cost structure and could deliver a blow to his business reputation.

His desperation seemed to be growing.

On June 10, one of Mr. Shoigu’s deputies announced that all formations fighting outside the Russian military’s formal ranks would need to sign a contract with the Russian Defense Ministry by July 1.

Mr. Prigozhin initially refused, but then Mr. Putin backed Mr. Shoigu’s plan. In the days that followed, Mr. Prigozhin released several audio and video messages showing what appeared to be attempts to reach a deal on his terms.

In one video, published on June 16, he shows himself delivering a “contract” to the Ministry of Defense in Moscow, but a receptionist behind a caged booth quickly closes the window in his face.

In the days before he led Saturday’s uprising, Mr. Prigozhin began expressing feelings of resignation, saying that none of the problems plaguing the Russian military would be fixed. He also talked about the nation rising up, saying that Mr. Shoigu should be executed and suggesting that the relatives of those killed in the war would exact their revenge on incompetent officials.

“Their mothers, their wives, their children will come and eat them alive when the time comes,” he said in a June 6 video interview, suggesting there might be a “popular revolt.”

He added, “I can tell you, honestly, I think we have only about two to three months before the executions.”