The man suffered lacerations in the attack in Sungai Buloh near Kuala Lumpur, the New Straits Times said Wednesday.
"It took us more than 30 minutes before the animal finally ran out of the mosque," a witness was quoted as saying.
The animal had also reportedly chased children outside the mosque before it was shot dead by a resident. Police were later informed of the incident.
Muslims make up 60 percent of the population of Malaysia. Pigs are viewed as unclean by Muslims and both breeding them and consuming their meat is haram or forbidden.