South Africa gained independence from British rule on May 31, 1961. The country had been a British colony since the early 19th century, and the process of decolonization began in the 1950s. In 1961, the country became a republic and withdrew from the British Commonwealth. However, the system of apartheid, a system of institutionalized racial segregation and discrimination, was implemented soon after independence and would remain in place for more than three decades. The end of apartheid and the transition to a multi-racial democracy began in the late 1980s, and the first fully democratic elections were held in 1994.