The shooting took place on Sunday evening in Kizlyar, a town of about 50,000 people on the border with Chechnya.
"The killed shooter was identified as Khalil Khalilov, 22, a resident of Rassvet village of Dagestan's Tarumovsky District", the statement, published on the town administration's website, read. The local Interior Ministry, however, said the gunman had acted on his own, according to the Interfax news agency.
The Russian RBK daily quoted an Orthodox priest saying the attacker had opened fire on churchgoers following an afternoon service.
Four women were killed on the site of the incident, while another woman subsequently succumbed to her wounds in hospital, the document added.
The gunman targeted worshippers at a Russian Orthodox church in the mainly Muslim region, although no motive has been established yet.
Spanish La Liga match report Eibar v FC Barcelona 17 February 2018
They need to get a statement win to show they are not going to let go of the top position in the standings any time soon. It was their fourth away victory in a row, after a 2-0 win at fifth-placed Villarreal and a 3-0 triumph at Real Madrid.
Next to his corpse lay two of his victims, covered in a white shroud.
Islamic State claimed responsibility for the shooting, its news agency Amaq reported, but did not provide immediate evidence for the claim.
In 2015, ISIS declared it had established a "franchise" in the North Caucasus.
Sunday's shooting comes exactly one month before the March 18 presidential election that Vladimir Putin is nearly guaranteed to win.
It has been the scene of an Islamist insurgency following separatist wars in the neighbouring Chechnya.