The tactics and technology of the Mughal emperor Babur at Panipat, 55 miles (90 km) north of Delhi, were cutting edge. He was invited to invade by disaffected relatives of Sultan Ibrahim Lodi, of the Afghan Lodhi dynasty, which ruled northern India at the time. He faced a much larger army equipped with 100 war-elephants and responded by stringing his troops out, with riflemen wielding matchlocks protected by earthworks in the gaps. At the front were wheeled cannons, protected by carts tied with ropes. His right flank was secured against the walls of Panipat, his left by trenchwork. When the Sultan ordered a charge, the elephants were terrified by the artillery, and trampled his own troops. With the enemy in disarray, yet tightly packed, Babur was able to order attacks on both flanks, while maintaining withering fire from his artillery. The Sultan was slain, and his forces routed, but victory did not end resistance to Babur: he would have to overcome an alliance of Afghan nobles and the Rajputs to secure his dynasty.