The Boers resisted British encroachments but were defeated in the Boer War ( 1899 - 1902 ) ; however , the British and the Afrikaners , as the Boers became known , ruled together beginning in 1910 under the Union of South Africa , which became a republic in 1961 after a whites-only referendum .