CAIRO — Egypt, Saudi Arabia, the United Arab Emirates and Kuwait are discussing the creation of a military pact to take on Islamic militants, with the possibility of a joint force to intervene around the Middle East.

The alliance would also serve as a show of strength to counterbalance their traditional rival, Shiite-dominated Iran. Two countries are seen as potential theaters for the alliance to act, senior Egyptian military officials said: Libya, where Islamic militants have taken over several cities, and Yemen, where Shiite rebels suspected of links to Iran have seized control of the capital.

The discussions reflect a new assertiveness among the Middle East’s Sunni powerhouses, whose governments have increasingly come to see Sunni Islamic militants and Islamist political movements as a threat.

The U.S. Arab allies’ consideration of a joint force illustrates a desire to go beyond the international coalition that the United States has put together to wage an air campaign against the Islamic State in Iraq and Syria. Saudi Arabia and the UAE have participated in those strikes in Syria. The officials said the alliance under consideration was not intended to intervene in Iraq or Syria but to act separately to address other extremist hot spots.

A Gulf official said the governments were coordinating on how to deal with Libya, and the talks were “ongoing on wider cooperation on how to deal with extremists in the region.”

Talks on an alliance against extremists are well advanced, Egyptian officials said. But the idea of forming a joint force is more distant, and there are differences among the countries over the size of any force, funding and headquarters, and over whether to seek Arab League or U.N. political cover.