He served in the Indian Civil Service from 1859 and acted as Judge of the High Court, Bombay. He retired when acting Chief Secretary to the Government of Bombay. Along with Allan Octavian Hume he was a founder of the Indian National Congress and served as its president in 1889 and 1910.
He was an unsuccessful parliamentary candidate in North Ayrshire in 1892 and served as Liberal Member of Parliament for Banffshire from 1893 to 1900.