Both while in prison, had agreed that if ever they get out alive, Ahmed would keep Iraq while Qara Yusuf would have Azerbaijan. During this time Azerbaijan was under Umar Mirza bin Miran Shah and Baghdad was under the administration of Abu Bakr bin Miran Shah, the two sons of Miran Shah. The two brothers were rivals and their rivalry allowed for the return of Sultan Ahmed Jalayir who took Baghdad after instigating an uprising from his headquarters at Hillah in late 1405.[citation needed]