The suspect, who was armed with a knife, was shot dead by police outside the mosque.
Three others, including a police officer, were injured during the incident.
Speaking to eNCA, a spokesperson for the Muslim Judicial Council of South Africa described the attack as "brutal", and said it was a "shocking and sad assault on what is probably the last day of Ramadan".
"Attack at a mosque in Malmesbury leads to 3 deaths. Provincial detectives are currently combing the scene for clues," the South African police service said on its official Twitter feed, Reuters reported.
The Muslim Judicial Council (MJC) said in a statement on their Facebook page just after 6am that it was “shocked to its core to learn of a brutal attack on the mosque.
“We can confirm that two people have been killed whilst in I'tikaaf and another regular musallee of the Masjied was injured. We do not have any further details as yet but we urge the community not to jump to any conclusions until clarity can be given.”
The MJC president and his deputies were on their way to the mosque to gather more information.
“Provincial detectives are currently combing a crime scene for clues following the death of two people at a mosque in Malmesbury during the early hours of this morning‚” said police spokesman Lieutenant Colonel André Traut.
“Malmesbury police were called out to a local mosque and found two people stabbed to death and several injured. The suspect‚ believed to be in his thirties and armed with a knife was still on the scene and charged at the police who tried to persuade him to hand himself over. He ignored the calls and tried to attack police. He was shot and killed in the process. His death will be investigated by IPID.”
There was no initial indication that the attack was in any way linked to an attack on a Shia mosque in Verulam‚ north of Durban‚ in May. One man was killed and two others were critically injured in the attack‚ in which three men stormed the building shortly after afternoon prayers in that incident.