EL-ARISH, Egypt — The Islamic State group claimed responsibility for attacking a remote Egyptian army outpost in the Sinai Peninsula with a suicide car bomb and heavy machine gun fire. The assault killed at least 23 soldiers in the deadliest attack in the turbulent region in two years.

The IS made the claim after nightfall Friday, saying in an online statement that it had carried out the attack as the Egyptian army was preparing an assault on IS positions in Sinai.

The coordinated attack suggested the Sinai-based militants are among the region’s most resilient, after IS in Iraq and Syria, where the so-called caliphate is now witnessing its demise. And it underscored the struggles Egyptian forces face in trying to rein in the insurgency.

Egypt has for years battled militants in Sinai, where the jihadis have exploited the vast arid and underdeveloped region and its disgruntled Bedouin population as an ideal incubator for Islamic militancy even before the IS affiliate has emerged at the forefront of the insurgency.

Friday’s assault began in the early morning, when a suicide bomber rammed his vehicle into a checkpoint at a military compound in the village of el-Barth, southwest of the border town of Rafah.

Dozens of masked militants then descended on the site in 24 Land Cruiser SUVs and opened fire on the soldiers with machine guns, according to security officials.

The shooting lasted nearly half an hour, the officials added, speaking on condition of anonymity because of regulations. The troops at the compound were estimated to have numbered about 60.

When the attack subsided, the militants apparently looted the checkpoint, snatching weapons and ammunition before fleeing, the officials said.

A number of militants were killed in the shootout, indicating the soldiers had fought back, and some of their vehicles were abandoned at the

scene.

The suicide blast at the start of the attack likely disabled the checkpoint’s military communications system, prompting one of the officers to use his own cellphone to record an audio message and send it to a colleague via WhatsApp, seeking help and asking for prayers. The message was later widely circulated on social media.

“This might be the last seconds in my life,” a man’s voice calmly says in the recording. “Quickly, oh men, anyone who knows how to reach the command center, notify them to use artillery as we are still alive.”

He then praises God and ends by saying “we will either avenge them or die,” referring to his fallen colleagues.

In Washington, State Department spokeswoman Heather Nauert said the United States strongly condemns the Sinai attack and continues “to stand with Egypt as it confronts terrorism.”

The security officials initially put the death toll at 10 but later told The Associated Press that more bodies were pulled from under the rubble of a nearby building that was used as a rest house for troops.

According to the IS statement, a second car bomber was used in the attack to strike an army convoy sent as a reinforcement to the embattled soldiers. The authenticity of the IS claim could not be verified but it was circulated by IS supporters online and by the U.S.-based SITE Intelligence Group, which monitors jihadi websites.

Earlier, Egyptian army spokesman Tamer el-Rifai confirmed the attack on his official Facebook page, saying that 26 army personnel were killed or wounded. He didn’t provide a breakdown.

He said the army on Friday foiled attacks that targeted a number of other checkpoints in the Rafah area and that 40 militants were killed.

Local Sinai residents, speaking on condition of anonymity for fear for their safety, said they saw Apache helicopters carrying out airstrikes across Rafah after the attack. On his page, al-Rifai posted photographs of allegedly slain militants, dressed in military uniforms, typically worn by IS extremists.

The Defense Ministry posted a video on its official website showing aircraft taking off and striking vehicles and positions allegedly belonging to the militants who carried out Friday’s attack.

The attacked checkpoint was set up two months ago to cut a key militant supply line between the outskirts of Rafah, where the district is known to have a heavy IS presence, and central Sinai, where militants have found safe havens in the mountains, according to tribal leader Hassan

Khalaf of the Swaraka, one of Sinai’s largest tribes.

The security officials said some senior officers had expressed opposition to the location of the checkpoint, arguing that it provided no real cover for the troops. The nearest army compound was an hour’s drive away, leaving the checkpoint with only the support of local armed tribesmen

from the Tarabeen, with their own small checkpoints nearby.

The area was also the site of fierce battles in the spring between the tribesmen and militants.

Despite the insurgency, IS has so far not succeeded in seizing territory in Sinai but maintains a strong presence in the western and southern areas of Rafah, on the outskirts of the town of Sheikh Zuweid, and even inside the residential areas of Sinai’s largest city, el-Arish.

Over the past months, IS has focused its attacks on Egypt’s Christian minority and carried out at least four deadly attacks that killed dozens, prompting army chief-turned-President Abdel-Fattah el-Sissi to declare a state of emergency in the country.

The restive northern Sinai has been under a state of emergency since October 2014, after Islamic militants killed more than 30 soldiers in a single attack. There was a significant decline in attacks this year in Sinai, with the one major assault killing eight policemen in el-Arish in January.

On July 1, 2015, IS carried series of attacks, killing over 50 soldiers in Sinai. IS said at the time that it attacked some 15 army and police positions and staged three suicide bombings. However, the army denied the high death toll.

The Sinai attack came as the Islamic State group is fast losing its once vast territory in Syria and Iraq. The group’s offshoot in Libya has been uprooted in months-long battles in the central city of Sirte, while its branch in Yemen has failed to seize territories or compete with its al-Qaida rivals.

Faced with the challenge in Sinai, the Egyptian government has accused several Arab and Muslim countries of financing and providing safe haven to Islamic militants — including Qatar, Turkey, and the Hamas group in neighboring Gaza Strip.

Hamas, which is seeking to improve relations with Cairo, quickly condemned Friday’s attack.

“We considers it a criminal, terrorist, and cowardly attack that doesn’t target Egypt only, but the security and stability of the entire Arab nation,” Hamas’ spokesman Fawzi Barhoum said.