Moroccan candidate, Ambassador Omar Zniber, received 30 votes, and his South African opponent, Ambassador Mxolisi Nkosi, secured 17 in a secret ballot in Geneva.
Prior to the vote, Nkosi said Morocco was the "antithesis of what the council stands for" and said the election of the North African nation would undermine the body's credibility.
Morocco, in turn, accused South Africa and some other African states of undermining its efforts to hold the position, a prestigious but mostly symbolic post.
"The Kingdom's election, supported by a large number of countries around the globe in spite of Algeria's and South Africa's efforts to counter it, demonstrates the trust and the credibility inspired by Morocco's external actions...," the Moroccan foreign ministry said.
The vote marks a rare public dispute in the African group whose turn it was to lead the 47-member council. It normally strives to take decisions as a bloc.
The dispute in part revolves around Morocco's sovereignty claim over Western Sahara, where the Algeria-backed Polisario Front is seeking independence. Rabat has denied allegations of rights abuses against its opponents there.
As part of a broader strategy, Morocco has been courting countries, including African neighbors, to build support for its policies for the former Spanish territory.
It has failed to garner the support of South Africa, which helped organize an event to promote self-determination for the Sahrawi people in Geneva last year.
Rights groups say Morocco's new role should prompt it to safeguard human rights at the highest level.
"In particular, Morocco must refrain from intimidating or carrying out reprisals against human rights defenders engaging with the U.N.," said Tess McEvoy, the Co-Director of the New York office of the International Service for Human Rights advocacy group.
The U.N. Human Rights Council, which convenes several times a year, is the only intergovernmental global body designed to protect human rights worldwide. It can increase scrutiny of countries' human rights records and authorize probes.