Cavagnari was the son of Count Louis Adolphus Cavagnari, of an old family from Parma in the service of the Bonaparte family, by his marriage in 1837 with an Anglo-Irish woman, Caroline Lyons-Montgomery. Cavagnari was born at Stenay, in the Meuse département, France, on 4 July 1841. He was killed on 3 September 1879 during the siege of the British Residency (then at Bala Hissar) in Kabul in Afghanistan.
He was educated at Christ's Hospital school, starting at the age of 10 years. He had obtained naturalization as a British citizen, and entered the military service of the East India Company. After passing through college at the Addiscombe Military Seminary, he served through the Oudh campaign against the mutineers in 1858 and 1859. In 1861 he was appointed an assistant commissioner in the Punjab region of British India, and in 1877 became deputy commissioner of Peshawar (now in Pakistan) and took part in several expeditions against the Pashtun tribes.
In September 1878 he was attached to the staff of a British mission to Kabul, Afghanistan, which the Afghans refused to allow to proceed through the Khyber Pass. In May 1879, after the British-Indian forces had invaded Afghanistan, and the death of Afghan Emir Sher Ali Khan, Cavagnari negotiated and signed the Treaty of Gandamak with Sher Ali Khan's son and successor, Mohammad Yaqub Khan. With this treaty, the Afghans agreed to admit a British representative to Kabul, and the post was conferred on Cavagnari, who also received the Star of India and was made a KCB. He took up his residence in July 1879. On 3 September 1879, Cavagnari and the other European members of the mission, along with their guards who were made up of The Guides, were killed after he refused the demands of mutinous Afghan troops. Cavagnari was survived by his wife, Lady Cavagnari (née Mercy Emma Graves), whom he had married in 1871.