A suicide bomber blew himself up as policemen in southern Russia gathered Sunday for the funeral of a slain colleague, killing at least seven of the policemen and badly wounding 12 other people, investigators said.

The funeral was held at the home of an officer who had been shot dead the night before by militants in Ingushetia, one of the predominantly Muslim republics in Russia's restive North Caucasus region.

In the nearby republic of Dagestan, two masked gunmen burst into a Shiite mosque during Saturday evening prayers and opened fire, wounding eight people, police said.

Shiites are a minority in Dagestan and throughout the North Caucasus, where an Islamic insurgency has raged for years.

The latest attacks took place as Muslims in Russia and around the world prepared for the feast that celebrates the end of the holy month of Ramadan.

Police investigating the shooting at the mosque in the city of Khasavyurt found a large homemade bomb and were able to defuse it Sunday morning, Dagestan police spokesman Vyacheslav Gasanov said. Militants have often rigged explosives to go off as police respond to a shooting or other attack.

In Ingushetia, Governor Yunus-Bek Yevkurov said the militants had killed the police officer to set up the suicide attack at the funeral the next day.

In Moscow, tens of thousands of Muslims gathered on the streets outside the city's main mosque for prayers on Sunday morning. An estimated 2 million Muslims, most of them from the North Caucasus and elsewhere in the former Soviet Union, live in the Russian capital, which has a population of 11.5 million.