At the outset the Dalai Lama was keen to establish good relations with Imperial Russia. His primary advisor was a Buriat Mongol who had been born a Russian subject and the British tended to blame him for influencing the Dalai against them. However, the expanding British influence northward from India worried the Dalai Lama a great deal and he seems to have viewed the Russians as a more distant and safer friend than the British. As staunchly orthodox as Imperial Russia was there had long been good relations with the Mongolians on the Russian frontier who shared the same style of the Buddhist faith as the Tibetans.
His fears were confirmed in 1904 when the British invaded Tibet and the Dalai Lama was forced to flee to Mongolia where he stayed in Urga (modern-day Ulan Bator) as the guest of the Bogd Gegen for over a year. However, the two theocrats did not get along well. The Dalai Lama led a much more devout life than the Bogd and with his good teachings was becoming more popular amongst the Mongols than their own spiritual leader. The Bogd Gegen also complained that it was costing too much to play host to the Dalai Lama and his court. In any event it was necessary for the Dalai to move on anyway given events that had taken place in his absence in relation to China.
After the British invasion the Chinese had declared the Dalai Lama deposed and claimed full sovereignty over the entire Himalayan region. The Dalai Lama was able to restore something of the status quo when he visited Peking and had an audience with Emperor GuangXu and the real power-behind-the-throne Empress Dowager Cixi. The Emperor stressed Tibet's status as a vassal of the Great Qing but the Dalai Lama refused to kowtow to the monarch and more or less left with the usual stand-off in place in 1908. He had just returned to Tibet and began putting the government back in order when Qing Imperial troops invaded in 1910 which forced the Dalai to flee again, this time to India (via Sikkim). However, Qing rule was short-lived as the following year the disastrous republican revolution broke out in China and brought down the Manchu dynasty.
By this time the Dalai Lama had become an astute master of international affairs and began dealing directly with China, Nepal, Sikkim, Bhutan and the British Raj. The Chinese republic apologized for the recent invasion and offered to restore the status quo but with the fall of the Qing the Dalai Lama basically said that all deals were off and the theocratic monarchs of Tibet and Mongolia recognized their mutual independence and promised support for each other in the event of an attack (he lived up to this promise when Chinese republican troops arrested the Bogd Khan as the Dalai Lama sent a force of Tibetan cavalry to aid the army of Baron von Ungern in liberating the Bogd and restoring Mongol independence). In domestic policy the 13th Dalai Lama made many modernizing innovations such as adopting a postal system, a more fair national tax code, an official national flag, a police force and he also abolished the death penalty and worked to wipe out corruption amongst the government officials. He also improved education, for the first time allowing secular subjects to be studied alongside religion and sent Tibetan students abroad to be educated along modern lines. He had a keen interest in new technologies and displayed the first signs that the secretive, hermit kingdom was starting to come out of its centuries of isolation.
By that time, however, the Dalai Lama had become quite old and he began looking forward to what would come after him. He predicted a bleak future for Tibet and listed many details that were (sadly) to come true after his death during the reign of his successor. He died on December 17, 1933.