TUNIS — Islamist politicians swept elections across the region in the aftermath of the Arab Spring, stepping close to power in Tunisia, Egypt, Libya and Morocco and undermining the thesis of Qaeda-style militants that violence offered the only hope for change.

Today, those politicians are in frantic retreat from Riyadh to Rabat, stymied by their political opponents, stalked by generals and plotted against by oil-rich monarchs. Instead, it is the jihadists who are on the march, roving unchecked across broad sections of North Africa and the Middle East. Now they have seized control of territory straddling the borders of Iraq and Syria where they hope to establish an Islamic caliphate.

And they are reveling in their vindication.

“Rights cannot be restored except by force,” the Islamic State in Iraq and Syria, the surging Qaeda breakaway group, declared last year after the Egyptian military removed President Mohamed Morsi of the Muslim Brotherhood from office. Islamists must choose “the ammunition boxes over the ballot boxes” and negotiate “in the trenches rather than in hotels,” the group proclaimed, calling the more election-minded Muslim Brotherhood “a secular party in Islamic clothes” and “more evil and cunning than the secularists.”

Thwarted by the old guard and eclipsed by the jihadists, moderate Islamists in Egypt, Libya and Yemen and among the Syrian opposition are finding themselves shoved to the margins. And they are debating what went wrong, how to salvage their movement and how to revive the dream of synthesizing Islam and democracy. In Syria, too, moderate and secular rebels have been eclipsed by extremists in their battle against President Bashar al-Assad.