Egyptian officials have portrayed a continuing militant insurgency as largely contained to a portion of the Sinai Peninsula that is all but sealed off by the military. But the militants have shown a continued ability to conduct devastating, large-scale assaults on Egyptian soldiers, while carrying out smaller, semiregular attacks in Cairo and other cities.

Egypt’s public fight against the militants has helped ease its strained relations with Western allies troubled by Mr. Sisi’s crackdown on Islamists and other political opponents.

On Wednesday, in a sign of the warming ties, Mr. Sisi made his first official visit to Germany, despite criticism of his human rights record by German lawmakers. The critics include the speaker of the Parliament, Norbert Lammert, who called off his planned meeting with Mr. Sisi before his arrival, citing “systematic persecution” of opposition groups with mass arrests and an “incredible number” of death sentences handed down by Egyptian courts.

In a joint appearance with Mr. Sisi, Chancellor Angela Merkel emphasized that Germany opposed the death penalty, saying, “Under no circumstances, even with regard to terrorist activities, should people be sentenced to death.”

She also stressed, however, the need to keep talking to countries like Egypt, noting its prominent role in the fight against terrorism. Highlighting Egypt’s importance to German business interests as well, Siemens, the German industrial giant, announced Wednesday that it had signed a $9 billion order — its largest ever — to supply Egypt with wind power and natural gas plants.

In an apparent effort to stave off any other discordant notes during Mr. Sisi’s visit, the Egyptian authorities prevented a human rights activist from traveling to Germany this week. The activist, Mohamed Lotfy, who is the executive director of the Egyptian Commission for Rights and Freedoms, said he had been scheduled to attend a round-table discussion on human rights at the German Parliament.

On Monday, as Mr. Lotfy tried to catch a flight to Frankfurt, en route to Berlin, he was stopped at passport control at Cairo International Airport, he said.