By the early 17th century, Shahaji Bhosale, an ambitious local general who had served Ahmadnagar Sultanate, the Mughals and Adil Shah of Bijapur at different periods during his career, attempted to establish his independent rule. His son Shivaji succeeded in establishing the Maratha Empire which was further expanded during the 18th century by the Bhat family "Peshwas" based in Pune, Bhonsle of Nagpur, Gaekwad of Baroda, Holkar of Indore, Scindia of Gwalior. At its peak, the empire covered much of the subcontinent, encompassing a territory of over 2.8 million km2. The Marathas are credited to a large extent for ending the Mughal rule in India. The Marathas defeated the Mughals and conquered large territories in northern and central parts of the Indian subcontinent. After their defeat at the hand of Ahmad Shah Abdali's Afghan forces in the Third Battle of Panipat in 1761, the Maratha suffered a setback. However, the Marathas soon regained lost influence and ruled central and north India including New Delhi until the end of the eighteenth century. The Third Anglo-Maratha War (1817–1818) led to the end of the Maratha Empire and East India Company ruled the country in 1819.