In OTL in March and early April 1888 Keir Hardie campaigned to be selected as Liberal candidate for the Mid-Lanark by-election but was unsuccessful. [1] A scenario is that he is selected as the candidate on 9 April and is elected as the Liberal member of parliament for the constituency on 27 April. When Gladstone becomes Prime Minister in 1892, he gives Hardie a junior ministerial post in his government, and Lord Rosebery promotes him to the cabinet when he becomes Prime Minister in 1894. When Campbell-Bannerman becomes Prime Minister in December 1905 he appoints Hardie Chancellor of the Exchequer. Following the resignation of Campbell-Bannerman in April 1908, Hardie becomes Prime Minister. The policies of his governments are much the same as those of Asquith's in OTL.
In this scenario there is a butterfly net for events outside the UK, so Archduke Franz Ferdinand is still assassinated in Sarajevo in July 1914 and subsequent events happen as in OTL. When German troops invade Belgium on 3 August, Hardie refuses British declaration of war on Germany. He is outvoted by his cabinet and resigns as Prime Minister and Lloyd George takes over. Hardie dies on 26 September 1915 at the age of fifty-nine as in OTL.
[1] See the book Keir Hardie: radical and socialist by Kenneth O. Morgan, London: George Weidenfeld and Nicholson Ltd, 1984.