He is best remembered for the "Ayrton controversy" over scientific facilities at Kew Gardens. Ayrton was the uncle of the physicist and electrical engineer William Edward Ayrton. Ayrton practised as a solicitor in Bombay, British India, and was called to the Bar, Middle Temple, in 1853.
He held office in William Ewart Gladstone"s first administration as Financial Secretary to the Treasury from 1868 to 1869 and as First Commissioner of Works from 1869 to 1873 and was sworn of the Privy Council in 1869.
Ayrton is best remembered for the so-called "Ayrton controversy". In an attempt, in the early 1870s, to reduce Government spending, Ayrton (as First Commissioner of Works) encouraged a proposal that the costly scientific functions of Kew Gardens should be transferred and that the gardens should be retained purely as a public park.
This prompted a confrontation with Joseph Dalton Hooker (Director at Kew), who enlisted the support of Charles Darwin and Charles Lyell, amongst other scientific luminaries. After debates in both Houses of Parliament, Ayrton was transferred to the post of Judge Advocate General and the proposal failed.
Ayrton remained as Judge Advocate General until the Gladstone government fell in February 1874.
He lost his seat in parliament in the general election of that year and never returned to the House of Commons. In the Palace of Westminster the lantern at the top of the Elizabeth Tower is called the Ayrton Light, lit when either House of Parliament is sitting after dark. lieutenant was installed in 1885 at the request of Queen Victoria so that she could see from Buckingham Palace when the members were sitting and named after Ayrton.
Foreign the last few years of his life he was a daily frequenter of the Reform Club.
He died at the Mount Dore Hotel, Bournemouth, on 30 November 1886. He is buried in Brompton Cemetery, London.