In 873, the Yang family of Shanxi kicked the Nanzhao were out of Sichuan. In 877 the Yang kicked them out of Guizhou. The Nanzhao retreated to Yunnan, and they slowly died. In 902, their chief minister murdered most of the royal family, including the heir apparent. In 937, Duan Siping seized power and created the Dali Kingdom.