Updated

Gunmen armed with rocket-propelled grenades attacked a border guard post Saturday in Egypt's western desert in a brazen assault that killed 21 troops deployed in the province along the border with neighboring Libya.

Egypt's President Abdel-Fattah el-Sissi called it a "terrorist attack" on soldiers defending the country's borders that will "not go unanswered.

"Terrorism will be uprooted from every part of Egypt," a statement from the presidency said. It declared a three-day mourning period.

The attack was the second in as many months on the same post, where a border guards company is based. Coming just over a month after el-Sissi took office, the attack is the worst single loss for military troops in recent history.

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

The attack Saturday came less than an hour before sundown.

El-Sissi, the former military chief, had vowed to fight terrorism, saying militant groups acting across borders were a threat not only to Egypt, but the region and the world.

Military and security forces have come under attack by militants in Egypt during the last three years of turmoil, with attacks increasing since el-Sissi removed his predecessor Islamist President Mohammed Morsi from office following mass protests against him. In the single worst attack on security forces, 25 members of the riot police were executed just over month after Morsi was ousted.

The Saturday attack targeted a military border checkpoint in Egypt's largest province, the western desert governorate of Wadi el-Gedid, that runs along the border with Libya to the west and Sudan to the south.

The checkpoint links the Farafra Oasis , an ancient caravan routes between Libya and Egypt, and the Bahariya Oasis, closer to the capital.

According to a statement on the official Facebook page of Brig. Gen. Mohammed Samir, a military spokesman, 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.

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.