The Trump administration sent shock waves through Cairo last month when it denied Egypt almost $100 million in military and economic assistance. The Senate followed up by slashing military assistance another $300 million. American decision-makers want to nudge Egypt to improve its record on democracy and human rights.

Fine. But with the stakes in the Mideast sky-high these days, America can’t afford to jeopardize an alliance that has been one of its most critical in the region for the past 40 years. Remember: Egypt has strong ties with Israel, takes a no-nonsense stance against Islamist violence and has helped fight the Islamic State.

Fortunately, there’s a way for the White House to demonstrate its support for Egypt in non-monetary terms. It can sanction two terrorist groups that continue to attack Egypt: Hasm and Liwaa al-Thawra. Such a move would send an important message to the people of Egypt and show America’s own commitment to fighting terror.

Hasm (Harakat Sawa’id Masr) is the Arms Movement of Egypt. The group announced its arrival in 2016 when it murdered Egyptian Police Maj. Mahmud Abdel Hamid and took responsibility via Facebook. It vowed “before God and the Egyptian people not to drop our weapons until our great people are liberated from the oppression of the military machine and its treacherous militias.”

The following month, it claimed responsibility after two gunmen shot at former Grand Mufti Ali Gomaa but failed to assassinate him. Gomaa had supported the army’s ousting of the Muslim Brotherhood in 2013 — forcibly, if necessary. A series of attacks followed, including a bombing near a police club, the assassination of a prosecutor and a policeman and a botched car-bombing of a judge.

In December, the group delivered a blow to Egypt’s already-flagging tourism industry when it detonated a bomb near the pyramids, killing six policemen and injuring three others.

Attacks claimed by Hasm continued through the summer. The instability has crushed tourism, and the economy continues to sag, making the government increasingly desperate for answers.

Then there’s Liwaa al-Thawra, the Brigade of the Revolution, founded roughly the same time as Hasm. Though far less prolific than Hasm, it has also attacked policemen at a checkpoint, assassinated a senior army officer and bombed a police-training center.

It’s clear the two groups meet federal-government criteria for the terrorist label, making them obvious candidates for Treasury’s targeted financial-sanctions program. They might also meet the State Department’s definition of a Foreign Terrorist Organization, though that designation process is more of a political minefield.

Critics may still oppose the move, given Egypt’s claims that the two groups are splinters of the Brotherhood. They’ll say Cairo’s severe crackdown on that organization accounts for its record on democracy and human rights — and the reason for the recent cut in aid. Targeting two associated groups will just escalate tensions.

Actually, an official connection between the Brotherhood, Hasm and Liwaa al-Thawra is still an open debate. Analysts have yet to make a definitive link. And Liwaa al-Thawra’s spokesperson recently denied his group’s alleged affiliation with the Brotherhood.

But even if Hasm or Liwaa al-Thawra are connected to it, that shouldn’t be a deterrent. If anything, it’s an opportunity for the White House to embark on a new and sensible Brotherhood policy. After all, the Brotherhood itself can be seen as a borderline terror group.

But it’s not homogenous. And sanctioning the entire network of branches worldwide — as some have called for — would be difficult, if not impossible. The right move is to target its overtly violent factions, while punting on the non-violent or predominantly political factions.

Meanwhile, let the White House mull over the question of aid to the Sisi regime. For now, it’s time to provide some support to an imperfect ally that’s battling terrorism. These groups deserve to be sanctioned by our federal government, regardless of any complaints about Egypt’s political flaws.

Jonathan Schanzer, a former terrorism-finance analyst for the US Department of the Treasury, is senior vice president at Foundation for Defense of Democracies.