In 397, by which time Lü Guang, then with imperial title, was facing a rebellion from Juqu Mengxun and Juqu Nancheng after listening to false accusations and executing their uncles Juqu Luochou () and Juqu Quzhou (), Duan Ye was the governor of Jiankang Commandery (建康, in modern Zhangye, Gansu). Juqu Nancheng put Jiankang under siege, but sent messengers to try to persuade Duan Ye that the Later Liang regime was becoming so corrupt as to be nearing destruction, and that with Duan's talents, he should be a leader. Duan Ye initially refused, but after 20 days of siege, no aid came from the Later Liang capital Guzang (姑臧, in modern Wuwei, Gansu). Duan Ye's advisors suggested that he accept Juqu Nancheng's proposal, and Duan Ye, who was also apprehensive of Lü Guang's officials Fang Gui () and Wang Xiang (), with whom he had inimical relationships, agreed. He took the title the Duke of Jiankang and changed era name, signifying a declaration of independence from Later Liang and the establishment of Northern Liang. He entrusted most important affairs of state to Juqu Nancheng.