He was first elected to Parliament as MP for the Stirling burghs in 1868 and became leader of his party in 1899. His premiership, which ended with his resignation only a few days before his death, saw the grant of self-government to the defeated Boer republics of Transvaal (1906) and the Orange River Colony (1907), the passing of the important Trade Disputes Act (1906), which exempted trade unions from certain liabilities in connection with strikes, and the entente with Russia (1907).