By 1948, South African politics had been for four decades dominated by veterans of the Anglo-Boer wars, with three defeated Boer generals serving as Prime Minister, namely Louis Botha, Jan Smuts, and JBM Hertzog. Botha and Smuts formed the South Africa party which was an alliance between moderate Afrikaners and English voters. Opposed to it was the National party headed by Hertzog which appealed more to poorer Afrikaners and some poorer English voters.
During the depression, the two parties formed a coalition, which survived until the outbreak of war in 1939, which South Africa entered by a cabinet vote decided by a margin of one. The hard Afrikaner core of the National Party broke off from the ruling "United Party". Highly sectarian (it did not field a single English candidate in 1948) it was considered to have little chance of winning in 1948 against the government which had just won the war.
The United Party however, like other Western governing parties that had ruled during the second world war, had many things going against it, including a serious recession, and concerns that it was out of ideas for the country's future.
Compared to this, the National Party offered the promise of ending English dominance of the civil service and the economy as well ending the competition that African laborers moving to the urban areas posed to poor Afrikaner workers. When the votes were counted the United Party had won a large popular vote victory, 547,437 (50.9%) for the United Party to 443,278 (41.2%) for the National Party. But when the seats were declared, the National party and its allies had won 79, compared to 71 for the United Party and its allies.
The National Party had taken advantages of one of the quirks of the South African system. The first was that seats were allowed to deviate from the population quota by a margin of 15% in either direction in order to accommodate local boundaries and to limit their geographical size. While an average of around 7200 votes were cast per constituency, the National Party only won 2 seats where more than 7200 votes were cast. The United Party by contrast won more than half its seats in districts where over 8000 votes were cast.
Similar results occurred in 1953 and 1958 with the United Party beating the National Party in the popular vote but losing out in the seat allotment because of the overrepresented rural regions. The rural Afrikaner boer became the power wielder despite the facts that South Africa was a multiethnic state where Whites were a minority divided between Afrikaners and English-speakers and the country was beginning to experience an urbanization boom. After 1958 the National Party became a power party which anyone who wanted to be in politics, regardless of political ideology, had to join if they wanted to be in power. From then on the National Party remained the dominant political party in South Africa with only weak opposition from the urban, liberal Progressive Federal Party and the rural and neo-urban (urban dwellers who still hold rural values) radical national conservative Conservative Party. White English-speaking South Africans and moderate Afrikaners began a slow but steady exodus from South Africa in part because of the feeling that the electoral system was gerrymandered against their interests.
South-West Africa, now known as Namibia, also played a role in the continued political domination by the National Party. Despite being never annexed by South Africa, Afrikaners and other European-ancestry Africans in South-West Africa were given the right to vote in South African elections. Identity pressure from the "White versus Black" Border War and the lack of an liberal White population meant that voters from South-West Africa overwhelmingly favored the Nationalist Party thus giving the party yet another boost to its hold on power.
In the 1980s the National Party created the House of Representatives for Coloureds and the House of Delegates for Indians as a way of giving some limited political power to these ethnic groups. The two houses managed to split non-Black minority opposition and gave the National Party some strong contacts with non-Black ethnic minority groups. Even in the 1990s there were leading Coloured politicians who opposed the abolition of apartheid because they felt it would loosen their grip on power and hurt the "better Coloured than Black" social hierarchy.
However, the inability and unwillingness of the National Party to give limited political power to Blacks (the homelands were seen as collaborationist regimes by most Blacks and most Blacks favored integration into the political system of South Africa-proper) only renforced Black and international opposition to the Apartheid regime. Pressure from the majority Black population combined with international sanctions finally led to the downfall of the racist system and the election of Nelson Mandela as President of South Africa in 1994.
See also: Dreams of a White Africa: South Africa versus Rhodesia and Native Lands - Reservations, Home Lands, and Republics (Part 1) for more information on the racial geography of Apartheid South Africa