An Islamic State group suicide bomber attacked a Shiite mosque in Sunni-ruled Saudi Arabia on Friday, killing 21 people and wounding 81 in an assault that threatens to fan sectarian tensions.

The bomber struck during the main weekly prayers in Eastern Province, where assailants linked to the Sunni extremist IS killed seven members of the minority Shiite community in November.

The interior ministry said a suicide bomber detonated a bomb at the mosque in the Shiite-majority city of Qatif, the official SPA news agency reported.

"An individual detonated a bomb he was wearing under his clothes during Friday prayers at Ali Ibn Abi Taleb mosque... in Qatif," the ministry spokesman said in a statement.

The health ministry was quoted by SPA as saying that 21 people were killed and 81 wounded, including 12 in critical condition.

IS said it was behind the attack, the first time the group has officially claimed an attack in Saudi Arabia, and vowed "dark days ahead" for Shiites, whom the group consider to be heretics, until militants "chase them from the Arabian Peninsula".

A statement published online said "soldiers of the Caliphate" were behind the attack by Abu Amer al-Najdi who "detonated an explosives belt" in the mosque.

The United States and UN Security Council condemned the bombing, but White House spokesman Josh Earnest said it was not immediately able to confirm it was the work of IS.

Shiite Iran demanded that the perpetrators be found and punished, and its Lebanese ally Hezbollah said it holds the Saudi authorities "totally responsible" for the bombing.

Pools of blood

News websites in eastern Saudi Arabia posted photographs of bodies lying in pools of blood, bloodied prayer rugs and damage inside the mosque.

Qatif hospital issued an urgent call for blood donations and called in off-duty staff to cope with the high number of casualties, an activist said.

Local resident Naseema Assada said worshippers were celebrating the birth of Imam Hussein, a revered figure in Shiite Islam, when the blast occurred.

"The people are very angry," she said, adding that they tried to stop police from entering the area.

Residents had feared such an attack was coming, she said, because the government was failing to curb hate speech on social media against the Shiite community, which complains of marginalisation.

"We don't want a repeat of what is happening in Syria or Iraq here," she said, referring to unrest in the two countries, sections of which IS claims as part of its "caliphate".

"This is our country and we love it."

The mufti of Saudi Arabia, the country's highest-ranking Sunni cleric, denounced the attack.

"It is a criminal act aimed at dividing the sons of the nation... and at sowing trouble in our country," he said on state television.

Hezbollah accused Saudi authorities of "sponsoring and backing criminal murderers" and of "failing to protect" its Shiite citizens.

'A matter of time'

A Saudi-led coalition has since March 26 been bombing Shiite rebels in Yemen who have overrun much of the country and forced the government to flee abroad.

Analysts said radical Sunnis in the ultra-conservative kingdom consider Saudi Shiites to be allies of the Yemen Huthi rebels.

"This (attack) was unfortunately only a matter of time," said Frederic Wehrey, a Gulf analyst at the US-based Carnegie Endowment for International Peace.

Shiites have not joined in the "wave of Sunni nationalism" that has followed the Saudi-led campaign against the rebels in Yemen, and are considered by radical Salafists as a "fifth column" for the Huthis.

Initial reports by witnesses said the suicide bomber appeared to be from Pakistan, but others said he was wearing what they described as traditional Afghan clothing.

Pakistani Prime Minister Nawaz Sharif, whose country has been a long-time ally of Riyadh, sent condolences to families of the victims and said in a statement "terrorists are enemies of humanity which also bring a bad name to Islam".

Eastern Province is an oil-rich region populated by many Shiites. It has been rocked by sporadic protests and attacks on security forces since 2011.

But in April, authorities said they arrested 93 jihadists, including 62 suspected of links to IS who were plotting attacks to "incite sectarian sedition".

Arrests of suspects with links to IS were also announced after gunmen last November killed seven Shiites, including children, in the eastern town of Al-Dalwa during a holy ceremony.