When the French invaded Egypt in 1798, Ibrahim fought against Napoleon's armies at the battles of the Pyramids and the Heliopolis but was defeated on both occasions. These defeats effectively ended his reign over the country, and he died in obscurity in 1816 or 1817, having survived Mohammad Ali Pasha's 1811 massacre of Mameluke leaders.