By Matt Murphy, BBC News
In the end, the Wagner mutiny lasted less than 24 hours. But the toxic cocktail of jealousy, rivalry and ambition that gave rise to it has been months, if not years, in the making.
The main characters of this drama were Yevgeny Prigozhin, the founder and leader of the Wagner paramilitary group, and the heads of Russia's enormous military - Sergei Shoigu and Valery Gerasimov.
Prigozhin - a former criminal who was associated with organised crime in the 1980s and for which he spent several years in prison - is a creation of the Kremlin who owes his enormous wealth to President Vladimir Putin.
Since he formed the Wagner mercenary group in 2014, he has become a key tool of Putin's desire to reimpose Russian influence across the globe. From the shadows, his forces - made up of hardened former Russian special forces - have propped up Putin's ally Bashar Al-Assad in Syria and helped roll back and replace French influence in Mali.
Until last year Prigozhin consistently denied mounting evidence that he controlled the group, launching lawsuits in British courts against Bellingcat journalist Elliot Higgins who accused him of running the private militia.
The deniable nature of his group's operations have made him popular with Putin and allowed him to build up his own power base, over the last year coming to rival that of the military and security elite that rule Russia.
A man at ease with violence, corruption and ambition - his rise is emblematic of the modern state built by President Vladimir Putin over the past 24 years.
But despite his increasing power, he has remained an outsider among Putin's small inner circle of advisers, unafraid to criticise officials in Moscow he sees as corrupt, lazy or both.
And he has reserved a particular hatred for the head of the military, Valery Gerasimov, and the Defence Minister Sergei Shoigu - a fellow outsider - for years.
Unlike most of Putin's key advisers, who tend to hail from the president's home city of St Petersburg, Shoigu was born in a small village on the Russian-Mongolian border.
Despite leading the Russian military for more than a decade, Shoigu never served in uniform, rising through the ranks of the Communist Party before becoming the head of Russia's emergency ministry in the 1990s.
Gerasimov, the third figure in this rivalry, is the ultimate army insider. He cut his teeth putting down a bloody rebellion in Chechnya in the 1990s, and is now the longest serving post-Soviet military chief.
Prigozhin's growing importance in projecting Russian power - and his group's ability to poach top special forces operators from the military by offering higher wages - are believed to have created tensions between the men for several years.
But it was really after the Russian invasion of Ukraine - and in particular post the bloody fighting in the meat grinder of Bakhmut, the battle where thousands of Wagner troops are believed to have been killed - that Prigozhin's hatred for the military elites has come to the fore.
The attempt to seize Bakhmut - a small city with a pre-war population of around 70,000 people - is puzzling. Most observers believe that it has limited military significance and some say the campaign was designed by Prigozhin to allow him to claim credit for a victory amid the military's faltering campaign.
He regularly accused Shoigu and Gerasimov "constantly trying to steal [credit for] Wagner's victory" in cities like Soledar, where thousands of paramilitary troops - often recruited from prisons - met their deaths.
And by contrast to his more bureaucratic rivals, Progozhin's often foul mouthed rants made him a personality that often caught the attention of the world's media. Leaked documents suggested that the Russian defence ministry was unsure of how to combat his messaging and increasing popularity.
But in the Kremlin, Putin was content to let it continue.
Allowing rivalries to simmer is very much Putin's style. He has long permitted competing power centres to fight among each other for influence, believing that it would prevent one faction from gaining enough prominence to challenge him directly.
Daniel Triestman, a professor of political science at the University of California, Los Angeles, wrote last year that the system created by Putin contains "tripwires" to prevent a coup, noting that officials "with armed men at their command lack the mutual trust to organise a conspiracy".
In this regime, Shoigu is kept in check by Wagner, while the mercenaries remain cowed by the military. At the top of the pyramid sits Putin, the chess master moving pieces around the board and maintaining balance in the system.
Meanwhile, Prigozhin has always been careful to avoid criticising the president directly, instead suggesting that Russia's litany of failures since the invasion in February 2022 were due to Putin being misled by his commanders.
For Putin, it was useful to allow the mercenary boss to pin the blame for the failing military campaign on underlings. The Russian president is believed to have privately criticised Shoigu and Gerasimov for the slow pace of the invasion.
But in recent months, Putin's long held strategy has appeared to fray.
Prigozhin - increasingly irate over his suspicion that the military was withholding ammunition from his forces as they attempted to complete the capture of Bakhmut - began posting more and more unhinged Telegram rants.
In one video - with the remains of dozens of dead Wagner fighters visibly surrounding him in the background - he raged: "You [expletive] who aren't giving us ammunition, you scum, you will eat their guts in Hell!"
"Shoigu! Gerasimov! Where is the... ammunition?... They came here as volunteers and die for you to fatten yourselves in your mahogany offices," he yelled in another video, seemingly attempting to blackmail Moscow by threatening to pull his forces off the front lines and abandon the fight for Bakhmut.
According to US intelligence documents leaked by American airman Jack Teixera, Prigozhin was summoned to a meeting with Putin and Shoigu on 22 February - the same day he posted the video among the Wagner corpses.
"The meeting almost certainly concerned, at least in part, Prigozhin's public accusations and resulting tension with Shoygu," one document read, using a different spelling of the defence chief's surname.
But the summit appears not to have had the desired effect.
Meanwhile, in Moscow, Shoigu was putting the finishing touches to a plan he hoped would reduce his adversary's influence for good.
The defence chief has sometimes faced criticism over his lack of uniformed service, but his knowledge of how to bend the Russian political system to his will is second to none.
He has remained in the Kremlin in one capacity or another since 1991, and few of Putin's advisers have spent longer at his side.
On 10 June he unveiled his plan, announcing that "volunteer formations" would be asked to sign contracts directly with the ministry of defence, integrating them with the military and giving them a new legal status.
The bill gave PMCs - or Volunteer Formations - until 1 July to comply and sign the contracts.
While the announcement didn't mention Wagner directly, it was widely viewed as a move to reduce Prigozhin's influence, immediately invoking the mercenary boss's fury.
"Wagner will not sign any contracts with Shoigu," Prigozhin raged. "Shoigu cannot properly manage military formation."
Nonetheless, the move will have set off alarm bells in Prigozhin's head. As a veteran political operator, Shoigu would not have moved to take control of Wagner without knowing he had the approval of Putin.
Prigozhin may have recognised that after months of indulging his attention seeking rants and criticism of the "special military operation", the president had finally decided to back his defence chiefs and marginalise his old ally.
Days later, Putin delivered his personal seal to the move, telling reporters in Moscow it was "in line with common sense" and had to "done as quickly as possible".
Some have suggested that this was the moment Prigozhin started to plan his mutiny, with the US-based Institute for the Study of War (ISW) saying he "likely gambled that his only avenue to retain Wagner Group as an independent force was to march against the Russian Ministry of Defence".
His troops soon escalated their campaign against the regular military, kidnapping a Russian field commander they accused of opening fire on Wagner troops.
US media reports that intelligence officials, having analysed Wagner movements for several days, briefed the Biden administration that Prigozhin was planning some sort of action.
And on Friday the mercenary boss unleashed his most damning criticism of the defence minister yet.
Departing from the false Russian line long promoted by Putin himself that Russia invaded Ukraine to ward off Nato and Nazis, Prigozhin raged that the conflict was nothing more than an excuse for Shoigu to win more medals and obtain the ultimate military honour of being promoted to the rank of Marshal.
"The Ministry of Defence is trying to deceive the public, deceive the president," he raged in a Telegram video.
That evening, less than two weeks after the defence ministry announced their plan to seize control of the Wagner Group, Prigozhin and his troops left Ukraine and took the Russian city of Rostov.
Some have speculated that Prigozhin agreed to end his rebellion after winning concessions from Putin, which could include changes at the top of the defence ministry, but whether this is true remains unclear.
Who would replace Shoigu and Gerasimov is equally unclear.
Gen Sergei Surovikin, once an ally of Prigozhin's but who spoke out against his mutiny, could be in line for a promotion. Known as General Armageddon, he commanded the invasion force briefly last year and was behind the largely ineffectual bombing campaign against civilian targets.
What happens to Prigozhin himself is another matter. His decision to halt his march of Moscow will likely anger many hard-line pro-war elements in Russia, while the ISW observed that "many Wagner personnel will likely be displeased with the potential of signing contracts" with the defence ministry.
And it is unclear whether he will be permitted to retain his enormous wealth. Reports in Russian media said some £38 million (NZD$78m) in cash was found during a raid on Wagner headquarters in St Petersburg, which Prigozhin said was used to compensate the families of dead troopers.
While this rebellion was largely strangled in its crib, and the military duo of Shoigu and Gerasimov have removed a major threat to their power, the conditions that gave rise to the mutiny remain.
Around 10 private military companies now operate in Russia, with their allegiance belonging to a collection of security officials, oil giants and oligarchs.
Shoigu is said to control his own company called Patriot PMC which operates in Ukraine and is in direct competition with Wagner, according to the US state department.
The loyalty of these groups to the regime must now be questionable at best, and may weaken the assumption that Putin's government is more capable of withstanding a long conflict in Ukraine than President Volodymyr Zelensky's government in Kyiv.
"The hopes of a part of the Russian elite, including, apparently, the president himself, that a long war is beneficial for Russia … are a dangerous illusion," said Ruslan Pukhov, an analyst with the Moscow-based Centre for Analysis of Strategies and Technologies.
"Prolongation of the war carries huge domestic political risks for the Russian Federation."
This story was originally published on BBC.