MOSCOW — Russia has approved a draft agreement with Egypt for Russian warplanes to use Egyptian military bases, according to a document released Thursday, a deal that would allow Moscow to further increase its military footprint in the Mideast.

The directive, signed by Prime Minister Dmitry Medvedev and published on the official portal of legal information, endorses the draft prepared by the Russian Defense Ministry and instructs it to sign the deal with Egypt when it’s ready.

The Russia-Egypt deal, which would allow each country’s warplanes to use air bases of the other, is to last five years and could be extended further if agreed.

For Egypt, the deal is significant as President Abdel-Fattah el-Sissi’s government has expanded military ties with Russia and signed deals to buy Russian fighter jets, helicopters and other weapons.

Russian Defense Minister Sergei Shoigu visited Cairo on Wednesday, noting that military cooperation between the two countries has increased recently as Egypt placed new orders for Russian weapons.

“We are pleased to note stable positive dynamics in the military-technical sphere,” Shoigu was quoted as saying during meeting of an inter-government commission on military-technical cooperation.

He also offered condolences for the massacre at a village mosque in Egypt’s Sinai Peninsula last week that killed 305 people during Friday prayers — the deadliest attack by Islamic extremists in Egypt’s modern history.

Shoigu emphasized the need to strengthen cooperation in fighting terrorism.

“We believe that it’s necessary to fight this evil together using all accessible means,” he said.

The local affiliate of the extremist Islamic State group has not formally claimed responsibility for the mosque attack, though the gunmen that mowed down the worshippers carried the black banner of the militant group. The IS affiliate has claimed responsibility for the October 2015 downing over Sinai of a Russian passenger jet that killed all 224 people on board, mostly Russian tourists.

IS said it blew up the plane with a bomb smuggled on board, a claim confirmed by Russian investigators. The bombing prompted Russia to cut commercial flights with Egypt, a heavy blow that decimated the country’s vital tourism industry.

Moscow and Cairo have held talks on boosting airport security and resuming the air link, but no agreement has been reached so far.

Egypt was Moscow’s closest Arab ally in the 1950s and 1960s, when nationalist leader Gamal Abdel-Nasser turned away from the United States and secured Soviet backing. Nasser’s successor, Anwar Sadat, broke ties with Moscow and evicted Soviet military advisers.

Under el-Sissi, who developed friendly ties with Russian President Vladimir Putin, Egypt has expanded economic ties with Russia and shown a renewed interest in Russian arms.

Russia has raised its profile in the Middle East region with a military campaign in Syria that has turned the course of war in Syrian President Bashar Assad’s favor. Russia has an air base and a navy supply facility in Syria, which it plans to expand.

El-Sissi has struggled to subdue the Islamic insurgency in Sinai. On Wednesday, he gave his security forces a three-month deadline to restore “security and stability” in the troubled northern part of the peninsula and authorized his new chief of staff to use “all brute force” against the militants.