Bukhara's sandcastle finally crumbled in the rising tide of tsarist military might. With its forces routed at the battle of Zerabulak near Katta Kurgan by Kaufmann's more professional troops, Bukhara lost control over the Zerafshan and the water supply that kept the city alive. In 1868, in the emirate's second city of Karshi, the emir signed the document that ceded Samarkand, Dzhizak and Katta Kurgan to the territory of Russian Turkestan, allowed Russians free trading concessions in the city and finally acknowledged Bukhara as a Russian protectorate. It received in return the rebellious city of Shakhrisabsz and some of the territory of the khanate of Khiva. For the next 40 years Russia gradually subsumed the surrounding lands as an army of antibodies envelops a malignant cell. In 1886 a decree was signed outlawing slavery in the emirate and two years later the Trans Caucasian Railway finally connected the Russian cantonment of Kagan with the large scale Russian trade and military centre that already existed in Tashkent.
But Bukhara was never formally incorporated into the Russian empire and the emir still held the power of life and death inside the city. Echoes of distant revolution eventually permeated the closed city walls "like the faint murmur in the hollow of a sea shell." A medley of ideas ranging from Islamic jadid reformism and Istanbul inspired pan-Turkism to Bolshevik-supported communism fermented in the desert heat. Finally they found voice and shape in the Young Bukharans, and their leader Faizullah Khodjaev, who began a series of reforms including a public printing press.
In March 1918 the Bolshevik governor of Tashkent, Kolesov, arrived outside the city gates and demanded the city be handed over to the Young Bukharans. The emir played for time, local mullahs called for a jihad against the infidel invaders and reinforcements were rushed in. Local Bukharans might have been excused a questionable loyalty to their vicious emirbut, following a theme that ran through the entire Soviet period, they preferred to follow their own Islamic tyrant rather than a godless foreign invader. The Bolshevik delegation inside the city was massacred to a man and several hundred Russian residents of Bukhara were later executed. The Bolshevik reinforcements turned tail (a retreat variously attributed to a lack of ammunition or divine intervention) and limped back to Tashkent, forced to relay the pieces of track they had just passed over in front of them-their western technology mutilated by holy guerillas. Bukhara had secured a two year reprieve from the Bolshevik advance and remained a closed oasis of a past era, stirred by a dangerous cocktail of White Russian exiles, young revolutionaries and an increasingly desperate emir.
During the next two years the Bolsheviks sent a total of 15 spies to Bukhara to investigate the rumoured existence of British Army advisers. One by one they were caught by the emir's network of informers, tortured and strangled. The 16th was Fred Bailey, a British spy who had somehow managed to get himself hired by the Bolshevik secret police, and then issued with instructions to hunt himself down. This master of double deals and disguises entered Bukhara in 1919 with a visa and two letters of introduction hidden in the back of his watch and a box of matches. In his breast pocket was the developer needed to decipher the invisible ink. Bailey had initially planned to stay in Bukhara and set up a British listening-post to complement the one in Kashgar. But after one month he crept out of the city at dawn disguised as a Turkmen nomad. It was a good piece of timing - nine months later, on 2 September 1920, Soviet troops arrived at the city gates, this time under the able command of General Mikhail Frunze.
After four days of bitter fighting, the Ark was largely destroyed, a mass revolutionary meeting was held in the Registan and the red flag was raised from the Kalon Minaret. The Emir Alim Khan had fled his summer palace for Afghanistan, desperately dropping his favourite dancing boys one by one in a vain effort to slow down the Red Army, in hot pursuit. On 6 September 1920 the first people's congress was convened in the courtyard of the Sitorai Makhi Khosa and the People's Republic of Bukhara was proclaimed.