William Allan was elected to the Queensland Legislative Assembly at the resulting by-election on 29 November 1881.
He held Cunningham until 21 March 1896 (the 1896 election), which he did not contest citing health and business considerations.
William Allan had a long history of suffering from asthma and bronchitis which were aggravated by an attack of influenza in September 1901, causing him to take a month's leave of absence from the Queensland Legislative Council to restore his health.
He travelled to Sydney hoping it would improve his health, but on arrival his condition worsened and his wife was summoned by telegram.
[11][12] His funeral was held on Monday 21 September 1901 at St Stephen's Presbyterian Church in Macquarie Street, Sydney, after which he was buried in the Waverley Cemetery.