In the Peshwa court he obtained his first opportunity of distinction, being attached in the capacity of diplomatist to the mission of
Sir Arthur Wellesley to the
Marathas. When, on the failure of negotiations, war broke out, Elphinstone, though a civilian, acted as virtual
aide-de-camp to Wellesley. At the
Battle of Assaye, and throughout the campaign, he displayed rare courage and knowledge of tactics such that Wellesley told him he ought to have been a soldier. In 1804, when the war ended, Elphinstone was appointed British resident at
Nagpur. This gave him plenty of leisure time, which he spent in reading and study. Later, in 1807, he completed a short stint at
Gwalior. In 1808 he was appointed the first British
envoy to the court of
Kabul, Afghanistan, with the object of securing a friendly alliance with the
Afghans against
Napoleon's planned advance on
India. However this proved of little value, because
Shah Shuja was driven from the throne by his brother before it could be ratified. The most valuable permanent result of the embassy was in Elphinstone's work titled
Account of the Kingdom of Cabul and its Dependencies in Persia and India (1815). After spending about a year in Calcutta arranging the report of his mission, Elphinstone was appointed in 1811 to the important and difficult post of resident at
Pune. The difficulty arose from the general complication of Maratha politics, and especially from the weakness of the Peshwas, which Elphinstone rightly read from the first. The tenuous peace between the Peshwas was broken in 1817 with the Marathas declaring war on the British. Elphinstone assumed command of the military during an important crisis during the
Battle of Khadki also called
Third Anglo-Maratha War and managed to secure a victory despite his non-military background. As reparations, Peshwa territories were annexed by the British. Elphinstone became the Commissioner of the Deccan in 1818. ==Governor==