Arguably, this balance wasn’t perfect; perhaps it might have been more effective to couple the condemnation for Mr. Sisi’s increasing authoritarianism with even greater counterterrorism assistance. In any case, American silence about the Sisi administration’s human rights record is not the answer. After all, Al Qaeda traces its roots to Cairo’s prisons under Egypt’s earlier repressive regimes.

In that context, we must hope that both the threat from the Islamic State and the problem of the Egyptian government’s repressions were part of the conversation in the Oval Office last month when President Trump met Mr. Sisi. An encouraging sign of a more productive relationship was the diplomatic back channel that reportedly resulted in Egypt’s release of an Egyptian-American aid worker.

Across the border in Libya, the Islamic State was able to exploit the chaos that has engulfed that country in the five years since Muammar el-Qaddafi was ousted to establish one of its most dangerous branches. Thanks to American airstrikes in support of government-aligned militias, the group was dislodged from its safe haven in the coastal city of Surt last year. In the last weeks of the Obama administration, the United States military undertook strikes to keep the extremists from regrouping.

America risks backsliding, though, on this progress if Mr. Trump acts on his recent statement that the United States has no role in Libya. The country still lacks a unified government, as a mix of the Islamic State, Qaeda affiliates, independent militias and criminal networks vie for advantage. The Government of National Accord, which does have international recognition, controls only part of the country and is buffeted by warring factions on both its eastern and western flanks. The forces in the east, led by Gen. Khalifa Hifter, are receiving support from Russia, increasingly assertive in the region, as well as from some Gulf countries.

President Barack Obama acknowledged that failure to plan for the day after Colonel Qaddafi’s demise was a mistake. But his administration led international efforts to support the Government of National Accord, and studiously avoided favoring one side in Libya’s civil strife. An American tilt now in favor of the warlord General Hifter could push Libya further into becoming a failed state, which would pose a greater threat to the security interests of the United States and Europe. Far from having no role, the United States should be using its influence with European allies and Gulf partners to build up the legitimate government and strengthen the rule of law in Libya. If it does not, Libya could look like Syria by this time next year.