South Africa is to have its first coalition government in the wake of an election that saw the late Nelson Mandela’s party lose its majority.