The robbers entered the police station in the southern village of Engcobo shortly after midnight, opening fire on the officers and seizing two others, who were later shot and killed, police spokesman Vish Naidoo said.
"During the early hours of this morning six people were killed when robbers attacked Engcobo police station," Naidoo told AFP.
"Five of the six were on-duty police officers. Three police officers were killed at the police station when robbers attacked the station and randomly opened fire on the members."
The attackers also shot and killed a soldier as they fled.
Attacks on police are common in South Africa, which has one of the highest crime rates in the world.
At least 57 police officers were killed in the line of duty in the 12 months between April 2016 and March 2017, according to the latest crime statistics available.