SARAH EL DEEBAssociated Press Published: July 20, 2014 4:00 AM

The attack targeted a checkpoint in the western desert governorate of Wadi el-Gedid, on the Farafra Oasis Road, more than 500 kilometers (310 miles) from Cairo, according to a statement on the official Facebook page of Brig. Gen. Mohammed Samir, a military spokesman. Farafra is the country's western most oasis, near the border with Libya.

Samir said one of the gunmen's rockets struck a cache of weapons at the checkpoint, sparking an explosion. He said the attack killed 21 troops and forces later seized two car bombs before they exploded.

He identified the gunmen as "terrorists," but did not elaborate.

Another military official said about 20 gunmen in weapon-mounted vehicles took the checkpoint by surprise. Ensuing clashes killed three of the attackers, the official and the state news agency MENA said. A medic said some of the bodies were burned.

[Article continues below]

The official and medic spoke on condition of anonymity because they were not authorized to speak to journalists.

MENA said this is the second time this border patrol company has come under attack from gunmen in the last few months. An earlier attack killed six troops, the agency said.

Egypt has long, porous borders with Sudan and Libya used by arms smugglers. Egypt has been flooded with weapons, mostly from Libya, following the 2011 civil war that toppled longtime dictator Moammar Gadhafi. Fighters from Libya also have come into Egypt from these borders, security officials say.

Egypt has vowed to tighten security along its borders.

This is the second brazen attack on troops in recent years during the holy month of Ramadan, when observant Muslims fast from dawn to sundown. In 2012, gunmen attacked a checkpoint near Egypt's border with Gaza and Israel, killing 16 soldiers. It was one of the highest number of troops killed in recent years in one attack.