JOHANNESBURG -- A man fatally stabbed two people on Thursday and wounded several others at a mosque near Cape Town before police shot and killed the attacker, authorities said.

The assailant, believed to be in his thirties, charged police who had tried to persuade him to surrender after the attack in Malmesbury in Western Cape province, police said.

"He ignored the calls and tried to attack police. He was shot and killed in the process," said a statement from police, who did not immediately comment on a possible motive for the attack.

A man said his father had been sleeping in the Malmesbury mosque when he was killed just ahead of the end of the holy month of Ramadan.

Suad Bassa, son of Ismail Bassa, said in an interview with the News24 outlet that the attacker also injured his brother when they confronted him.

"It's sad, but Allah has taken him away in the place that he loved the most," Suad Bassa said.

News24 video footage showed the body of the attacker lying in an open area cordoned off by police tape.

On May 10, assailants killed one person and injured two others in a similar attack on a mosque in the eastern town of Verulam, near Durban. No arrests have been made.

South Africa's Muslim Judicial Council said it was "shocked to its core" by the attack in Malmesbury and that its president and his deputies were heading to the mosque.

"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 council said.

The Democratic Alliance, an opposition party that runs Western Cape province, condemned the attack and said South Africans have the right to religious freedom.

"An attack on people while they worship is a direct attack on the constitution and the freedoms we enjoy in this country," the party said.