Cairo: Egypt vowed on Sunday to punish the attackers who killed 22 border guards in its western desert near the frontier with restive Libya.

Militants firing rocket-propelled grenades and machine guns attacked a checkpoint, 630 kilometres west of Cairo, on Saturday, killing 22 soldiers and wounding another four.

The military, which updated its previous death toll, said the soldiers were killed when an RPG set off an explosion in an ammunition depot at the Al Farafrah border security post.

Egypt’s presidency said “the heinous crime that took these brave souls and spilled their blood will not go unanswered”.

“Terrorism will be uprooted from every part of Egypt. All those responsible for perpetrating these acts and acting outside of the law will receive their rightful punishment,” it said.

Egypt authorities declared a three-day period of mourning from Sunday.

The attack followed repeated warnings by officials of a possible spillover of violence from across the border with Libya, where relentless bloodshed has sparked fears of all-out civil war.

Libya has been awash with weapons and gripped by unrest since the 2011 Nato-backed uprising that toppled dictator Muammar Gaddafi, with rival militias which ousted him vying for control.

Egypt’s porous western border with Libya stretches for more than 1,000 kilometres.

In August 2012, gunmen killed 16 Egyptian border guards on the frontier with Israel.

And since the army ousted Islamist president Mohammad Mursi in July 2013, Egypt has been rocked by deadly bombings and shootings.

Most of the assaults have been claimed by jihadists amid a bloody crackdown by the authorities on Mursi’s supporters.

The police crackdown has left more than 1,400 people dead in street clashes, upwards of 15,000 jailed and some 200 sentenced to death.

Mursi and several other senior leaders of his Muslim Brotherhood movement have all gone on trial.