In May 1497, Babur led his army from Andijan into the territory of Sultan Baysonqor Mirza and after various successes encamped at Yam, a village not far from Samarkand.
On one of these occasions a party that Babur had sent to the Lovers Cave to surprise the city by night, on the treacherous invitation of some of the townspeople, fell into an ambush by which some of his bravest soldiers were slain and others taken prisoner and afterwards put to death.
He therefore decided to break up from his exposed positions before the city and to erect temporary huts for his troops in some neighboring forts by which means they could still keep Samarkand in a state of blockade.
[2] At this critical moment, an Uzbek force arrived at Samarkand on the request of Baysonqor Mirza, under their leader Muhammad Shaybani, who would become Baburs' nemesis.
Babur, though his forces were dispersed, resolved to show a bold countenance, put the troops that were with him in battle formation and marched out to face the enemy.
Masud Mirza wanted to prevent that his brother and rival would be able to unite himself with a protector so formidable as Khusroe Shah, and made an attempt to seize him.
Baysonqor Mirza, the fugitive prince passing through the territory of Hissar, escaped with difficulty, though with the loss of several of his followers who fell into Masud's hands.
[2] He finally, however, did succeed in reaching Kunduz where he was well received by Khusroe Shah, who had been the chief minister of his father but, at that time engrossed with his own schemes of power and conquest, regarded Baysonqor Mirza as a fit instrument for his soaring ambitions.
As soon as Babur heared of the flight of Baysonqor Mirza, he rallied his troops from their encampments towards Samarkand and took the city without opposition by the end of November 1497.
Ahmed Tambol later rebelled and took over his Kingdom of Fergana, supporting Babur's brother Jahangir Mirza as the new king and joined by Uzun Hasan.