Officials said Tanzania was on high alert for al-Shabab attacks after the group claimed an attack on a university in neighboring Kenya this month that killed 148 people.
Police Commissioner Paul Chagonja told Reuters the suspected members of the al-Qaida-linked group had been arrested on Tuesday night in Kilombero district, Morogoro region, about 200 km (125 miles) east of the commercial capital Dar es Salaam.
Morogoro regional police chief, Leonard Paul Lwabuzala, said in a statement that one member of the group was lynched by a mob as he was pursued by the police.
“The suspects arrested at a mosque were found in possession of 30 sticks of explosives, detonating cord, a black flag, military uniforms, masks and swords,” Lwabuzala said.
Tanzania has been spared the level of assaults by al-Shabab militants seen in Kenya although there have been sporadic attacks on tourists.
Unlike Kenya, Tanzania, which is roughly evenly split between Christians and Muslims, has not sent troops to Somalia and it does not share a border with the Horn of Africa nation.
Al-Shabab has said it has targeted Kenya to punish the country for sending troops to Somalia where they have battled the militants as part of an African Union peacekeeping force. It said other contributing African nations could also be targeted.