Sergei Melikov, governor of the Dagestan region, said: “This is a day of tragedy for Dagestan and the whole country.”
Russia's national “counter-terrorism committee” said the attack was carried out by "terrorists".
Both the synagogue and church were also set on fire by the gunmen according to police.
According to reports in Russia's state media two sons of the head of central Dagestan's Sergokala district were among the attackers.
They are understood to have been caught by the police.
In the past Dagestan has been the scene of Islamist attacks.
Three months ago some 145 people were killed in an attack claimed by the Islamic State.
The attack on a concert hall near Moscow was Russia's worst attack in years.