Viljoen was elected to the Legislative Council (Upper House) of the
Cape Parliament in 1903, for the South Western Circle. For the year he was on the council, he worked primarily on healing the wounds between the English and Afrikaner ethnic groups after the
Anglo-Boer War. In 1904 he was elected to the House of Assembly (Lower House) of the Cape Parliament, for the Caledon district. In this capacity, he worked on conservation (banning the sale of certain species of wild flower, and cooperating on the founding of
Kirstenbosch National Botanical Garden). Viljoen was part of a liberal grouping in parliament, who strongly supported women's suffrage and the extension of the multi-racial
Cape Qualified Franchise. His most famous contribution was in being part of the first attempt to extend the vote to women of all races, with fellow MPs
JW Sauer and
James Molteno on 4 July 1907. Viljoen was in fact the MP who first tabled the motion. At the formation of the Union of South Africa, he was also elected to the Senate, where he continued his policies of pushing for a more inclusive, multi-racial, and gender-sensitive future for the country. He was knighted by the British king in 1916. The Viljoen pass between Elgin and
Villiersdorp is named after him. His descendants still farm on Oak Valley, Elgin, under the surname Rawbone-Viljoen after the husband of his daughter Johannah Jakobmina Krugerina, George Crundwell Rawbone, changed the family's surname to Rawbone-Viljoen to comply with Viljoen's will and testament, viz that the farm can only be inherited by a descendant who bears the surname "Viljoen". == Later life ==