Ayers served as attorney of Fergus County, Montana from 1905 to 1909, and Judge of the Tenth Judicial District of Montana from 1913 to 1921. During the First World War, Ayers served as chairman of the Fergus County Exemption Board. He was the Justice of the State supreme court from January 1922 until his resignation on November 22, 1922, when he resumed ranching and the private practice of law in Lewistown. In 1924, he ran for Governor of Montana, but lost in the Democratic primary to John E. Erickson, who would later go on to win the general election. Ayers challenged him in the primary again in 1928, and was defeated by less than a thousand votes by Erickson, who again won the general election.