In the period during the collapse of the Ming Dynasty and the coming of the Manchu Qing Dynasty, China was riven by a series of rebellions and temporary kingdoms established by provincial warlords.
One of the most notorious of these warlords was the peasant Zhang Xianzhong, from Sichuan province, who proclaimed himself emperor of Daxi. Sun, born in Mizhi, Shaaxi province, was one of Zhang's favorite generals. Zhang, himself orphaned as a child, adopted Sun as his heir.
He is credited with both encouraging and trying to moderate Zhang's policy of exterminating the entire civilian population of the region, which made Zhang one of the worst mass murderers in history. After Zhang's death Sun became head of the army and king of Qin, and invaded Yunnan and Guizhou provinces against the invading Qing Manchus, making his capital in Kunming, but he surrendered to the Qings, who gave him the title King of Justice.