Security officials on Friday said Abd Allah Ahmad Yahia Zeid Ghassan threw two grenades and sprayed bullets at worshippers before killing himself.
He fled the scene of the attack and barricaded himself in his home, besieged by local residents and police, before turning his gun on himself.
"According to initial reports, the individual was suffering from psychological troubles and had family problems," an official said.
In the man's pocket, police found a letter justifying his behaviour by a desire to "rid his village of corruption."
Last August, three worshippers were killed and about 50 others wounded when a man threw a grenade in a mosque in Omran province, north of capital Sanaa.
In July, eight people were killed and two others wounded when a Yemeni opened fire in a mosque south of the capital.
Two similar incidents in 2001 killed 10 people and wounded 17 others at mosques north of Sanna and in southern Yemen.