The racist polity of apartheid was introduced into South Africa after Dr Malan's National Party was elected into power in 1948 and effectively gave the overwhelming majority of the blacks population no rights or freedom; the aim of apartheid was to keep white domination over all other races in South Africa whom they deemed to be "second class".
The end of apartheid in the 1980s and 90s happened for many reasons, none of them simple. Continued black resistance was certainly a part of it, the whole time apartheid had been legal, blacks had fought against it and never given up, even in the face of seeming failure. Resistance grew to an all time high in the 1970s and early 80s and made it extremely hard for the government to govern South Africa effectively.
There was also a lot of pressure placed on South Africa by other countries to change its policies, they saw what was happening and did not approve of the way blacks and other races were being treated. Many of these countries had also had problems with racism against blacks but had reformed its laws long before South Africa had event considered it.
Finally, the changes within South Africa itself also helped to reform the policy of apartheid. The government and people had woken up to the fact that socially, as a country they were going backwards while the world was progressing and realised that changes had to be made.
One major reason for the end of apartheid in South Africa was the continual resistance from the black population. Essentially black resistance made South Africa ungovernable and change had to be made. The government could no longer control the black population who would not sit back and let their race be discriminated against any longer.
The main organization that challenged white rule was the African National Congress (ANC). This organization was founded in 1912 to unite all black Africans and protect their rights through the use of peaceful demonstration.