Five people have been killed and several others injured in a gun attack on a crowd of churchgoers in Dagestan in southern Russia, local police confirmed. The shooter was killed by security forces.

The shooting happened in the city of Kizlyar, a provincial capital in the Republic of Dagestan. The gunman opened fire with a hunting rifle at a group of people leaving a church ceremony dedicated to the end of the Russian folk festival of Maslenitsa, which marks the start of Lent for Russian Orthodox Christians.

The attacker shouted "Allahu Akbar" [God is great] as he opened fire on worshippers, father Pavel, the church's senior priest, told Russian RBC news portal.

An eyewitness to the shooting, Oksana, told RT it happened right in front of a Christian church. The gunman targeted people as they were leaving, but luckily many of the churchgoers managed to take cover inside the building, giving more time for the security guards to respond to the attack.

“There were a lot of people there, moms with little children, elderly people. I believe God saved us, not allowing the man to get inside the church,” the woman said. She added the gunman was killed as he was attempting to flee the scene.

The attacker was identified by the Kizlyar city administration as Khalil Khalilov, a resident of a local village. It said that Khalilov first tried to break into the church, but when the doors were shut, he opened fire at those who were leaving the service.

WATCH: CCTV captures the moment shooter opens fire on Russian churchgoers (DISTURBING VIDEO)

The death toll of the attack has risen from four to five people after a woman, who was among those delivered to the hospital, “died on the operation table,” the Dagestani Health Ministry told Interfax. The health ministry initially said five people were wounded in the shooting and hospitalized. The interior ministry announced two of them were security personnel who responded to the shooting and gunned down the attacker.

The four fatalities on site were all civilian women leaving the church, according to law enforcement. Interfax also cites a source as saying that the gunman had a female accomplice who fled before the shooting started.

The Russian Investigative Committee says the gunman has been identified as a local resident in his early 20s.

The head of the Russian Orthodox Church, Patriarch Kirill, was “stunned” by the attack in Kizlyar and demanded the most thorough investigation of the incident, Patriarch’s spokesman, priest Aleksandr Volkov, wrote on Telegram.

"The Primate of the Russian Orthodox Church considers this terrible crime, committed on the eve of the Great Lent, a provocation aimed at instigating confrontation between Orthodoxs and Muslims, who have been coexisting peacefully for ages in the Caucasus,” the spokesman wrote.

Dagestan’s Muslim Spiritual Authority has called the shooting a “tragedy,” saying that it condemns all manifestations of violence. “We express our most sincere condolences to the relatives of those who were killed or injured,” the Muftiyat said in a statement.It said the perpetrator was an adherent of Wahhabism, a hardline interpretation of Islam.