Former grand mufti Sheikh Ali Gomaa speaks to reporters at his home Friday after gunmen targeted him for assassination in a western Cairo suburb. A bodyguard was wounded in the attack. (AFP/Getty Images)

Egypt’s former grand mufti survived an attempt on his life in a western Cairo suburb when two masked gunmen opened fire as he was walking toward a mosque to hold Friday prayers, officials said. It was the first assassination attempt against a high-profile figure in the Egyptian capital this year.

Sheikh Ali Gomaa was unharmed in the attack, and the two gunmen fled the scene outside the Fadel Mosque in the city’s Sixth of October district, Capt. Ahmed Alaa said.

The Interior Ministry said the gunmen had been hiding in a small park nearby and opened fire from there. One of Gomaa’s bodyguards was slightly wounded, the ministry said, adding that Egyptian security forces were searching for the perpetrators.

Later Friday, a little-known group that calls itself Hasm claimed responsibility for the attack, saying in an online statement that it aborted the plan because of the presence of civilians near Gomaa. It said the operation sought to end the “military occupation of Egypt and militias of [President] Abdel-Fatah el-Sissi.”

The statement carried photographs of the two gunmen, seen pointing their rifles from inside a garden lined with palm trees. The group’s affiliation is not known, but it claimed responsibility last month for the killing of the police chief in Fayoum, a town 50 miles southwest of Cairo.

Talking to the local CBC network, the cleric later said it wasn’t the first assassination attempt against him and that he has received death threats before.

Cairo’s Al-Azhar, the Sunni Muslim world’s seat of learning, issued a statement condemning the attack as “criminal.” Mufti Shawki Allam blamed “extremism and terrorism” for the attack.

“They only know the language of blood and destruction,” Allam said.

Gomaa was a key supporter of the military’s ouster in 2013 of Islamist President Mohamed Morsi. In public speeches, he has been advocating the use of force against Morsi’s group, the Muslim Brotherhood. Since Morsi’s ouster, Egypt has been carrying an extensive clampdown on Islamists, Morsi’s supporters and other government opponents.

Over the past several years, Egypt has also battled a rising insurgency, with a string of suicide bombings targeting security headquarters and the army. Then-Interior Minister Mohamed Ibrahim survived an assassination attempt in 2013, while the country’s state prosecutor was assassinated in a car bombing in 2015. Egypt’s Islamic State affiliate — formerly known as Ansar Beit al-Maqdis — has claimed responsibility for most of the attacks.

On Thursday, Egypt’s military announced that it killed the top Islamic State leader in the volatile Sinai Peninsula and dozens of members of the militant group in an operation.