Four people were killed in Saudi Arabia on Friday afternoon when a suicide attacker detonated outside a Shia mosque in the Eastern Province, according to official reports.

However, a much higher death toll was avoided because two young civilian guards stopped the bomber entering the al-Anoud mosque in provincial capital Dammam, according to locals at the scene.

The attack was later claimed by Islamic State.

Early on Friday afternoon a male attacker attempted to enter the only Shia mosque in Dammam wearing an abaya – a black cloak worn by women – but found the female entrance was closed, witnesses told Middle East Eye.

The attacker then returned to the main gate of the mosque and tried to go inside, where an estimated 1,000 people were attending Friday prayers. He was barred from entering by two young men – Mohammed Hassan Ali bin Isa and Saeed Abdel Jaleel Jumaa al-Arbash – who had been tasked with manning a civilian checkpoint.

The attacker then detonated his bomb, around one to five metres outside the mosque entrance, killing himself and the two civilians guards, as well as one other person whose identity remains unknown.

The two young men were hailed as heroes by those at the scene.

“They saved a lot of lives by stopping the bomber from getting inside the mosque,” a local, who asked to remain anonymous, told Middle East Eye. “They are both heroes.”

Mohammed Hassan Ali Bin Isa (L) and Saeed Abdel Jaleel Jumaa al-Arbash (R) (Twitter) Saeed had recently returned from studying in the United States and got married “a few days ago,” according to locals.

Mohammed’s mother, Kowther al-Arbash, is a high-profile writer for Saudi daily al-Jazira. News of her son’s death was greeted by an outpouring of support online for Arbash.

A statement from Saudi Arabia's Interior Ministry, however, said that the state's security services had been responsible for "foiling" the mosque attack.

Footage posted online reportedly recorded the moment of the explosion, as heard from inside the mosque.

لحظة التفجير الارهابي الذي استهدف مسجد العنود في الدمام ..#تفجير_العنود pic.twitter.com/Em9kbyuwZe — mohammad boland (@mohadboland) May 29, 2015

Middle East Eye interviewed a local resident about the bombing, whose house is 1 kilometre away from the mosque.

The bombing is the second to hit the kingdom’s Shiite-majority Eastern Province in a week.

Last Friday, on 22 May, a suicide attacker detonated his explosive vest inside the Imam Ali mosque in the town of Qudaih, killing 21 people and injured over 100 others, in an attack later claimed by Islamic State.