Haniyeh would like to meet with former South African President Nelson Mandela during the trip, according to Ahmed Yousef, Haniyeh's political adviser.
The invitation was issued by visiting South African Intelligence Minister Ronnie Kasrils, who met with Haniyeh.
"We stand by you and support you," Kasrils said of the new Palestinian unity government, a coalition of Hamas and the Fatah movement of Palestinian Authority Chairman Mahmoud Abbas.
"We in South Africa look forward to you being able to lead a delegation to our country," Kasrils told Haniyeh at a joint news conference. Haniyeh accepted the invitation, but no date was set for a trip.
Another government official from Hamas, Mohammed Madhoun, told a pro-Hamas news Web site that Haniyeh planned to visit South Africa as a part of a tour to Malaysia, Indonesia and Turkey. Haniyeh may also informally visit Switzerland at the invitation of a civil society group, Madhoun said.
Kasrils demanded that the international community lift its aid embargo on the PA, imposed after Hamas came to power in elections last year and refused to accept international demands to recognize Israel, renounce violence, and abide by prior agreements.
The national unity government formed in March has also failed to meet the demands.
"The people of Palestine are facing a collective punishment by those who were not happy with the result of a democratic election," he said.
But Kasrils said "the South African government believed the government of Mr. Haniyeh and President Abbas have gone a long way to meeting those requirements as we understand them."
South Africa has been an early supporter of the new Palestinian government. But the South African official's comments drew Israeli criticism. Foreign Ministry spokesman Mark Regev said inviting leaders of a movement still dedicated to Israel's destruction would entrench extremist positions.
Regev said the move gave legitimacy and recognition to an unreformed extremist Hamas leadership.