Morocco’s King Mohammed VI, right, and his brother Prince Moulay Rachid in 2015. (Abdeljalil Bounhar/AP)

After an unprecedented five months of post-election gridlock without a government, Morocco’s King Mohammed VI dismissed prime minister-designate Abdelilah Benkirane on Wednesday. Benkirane’s Islamist Party of Justice and Development (PJD) won a plurality of seats in the legislative elections in October 2016 and appeared well on its way toward a second consecutive term at the helm of the Moroccan government.

But negotiations did not go as planned. Benkirane’s dismissal came just a few days after he refused to acquiesce to a major alliance party’s demands to widen coalition talks. The shake-up was widely seen as an attempt by the monarchy and its deep state network of elite allies — known as makhzen — to regain political power. Although the decision may have been unexpected, the regime’s logic is familiar. As Benkirane and his successor know well, they must play by the monarch’s rules.

As it has done in the past, the regime is seeking to reconfigure the Moroccan political scene. The PJD, especially under Benkirane, may have become too popular and adversarial for the regime’s liking. The party has also increasingly reengaged Moroccans politically, building a formidable base in a country where depoliticization is a state policy.

After the dismissal, a palace communique lauded Benkirane’s service to the country, his “effectiveness, competence and self-sacrifice,” adding that the king would task another member of the PJD to form the government. Benkirane accepted the royal decision, in an austere tone: “This is our king and he came to a decision under the framework of the constitution, which I’ve always expressed support for, … I’m going to perform ablution, pray, and continue working on the ground.”

Benkirane, as secretary general of the party, then called for a special national council meeting of the PJD on Saturday. But before the party could gather to decide on its next move, the king further limited its options by tasking Saadeddine Othmani, the former secretary general of the PJD and current head of the party’s national council, with forming the new government.

Addressing the press at the special national council meeting Saturday, Benkirane resolutely declared that his government work is over. By the end of the day, the PJD national council unanimously supported Othmani’s appointment. Both Benkirane and Othmani reaffirmed the party’s dedication to its Islamic reference, belief in gradual reforms and support for the monarchy.

The palace may expect Othmani to yield to some of the demands of the palace-aligned makhzen parties led by the National Rally of Independents (RNI). Benkirane feared the proposed RNI coalition would lead to greater internal regime control, especially with Driss Lachgar’s Socialist Union of Popular Forces (USFP) as an obstructionist bloc within the PJD-led government. The choice of Othmani suggests the gridlock was more about Benkirane than the PJD. Othmani, who was briefly minister of foreign affairs in Benkirane’s first government, is seen as more of a consensus-building politician.

And although it did not immediately cause discord within the cohesive PJD, the removal of the beleaguered prime minster may be just the first phase in the regime’s attempt to reorder the political landscape and slow the pace of post-Arab uprisings reforms. Disrupting the government’s formation could eventually pave the way for new legislative elections that bring a makhzenite political elite to power.

The PJD’s 2011 and 2016 electoral successes bolstered confidence in its formidable grass-roots mobilization and ability to win elections. Although the PJD could have mobilized behind the revolutionary February 20 Movement in 2011, it chose to pursue participation in elections. In doing so, the PJD followed a “third way,” opting to join the political system in partnership with the palace and articulating a “revolutionary” discourse focused on incremental reforms rather than outright revolution.

But the party’s meteoric rise was not always in line with makhzen and palace interests. During the 2016 campaign, the populist Benkirane promoted his party as that of the people in direct contrast to the palace-loyal parties. Walking a rhetorical tightrope, the PJD expressed loyalty to the king, while criticizing the political system for tahakoum, political manipulation. In the hours before the official tallies were announced, Benkirane boldly suggested the results might be subject to state manipulation. After it was clear that his party had won the plurality of the seats, Benkirane hailed the results as a victory for democracy and a further proof of public approval of his government’s performance.

The royal discharge of Benkirane speaks to the regime’s deep control of the political system, which is intentionally fragmented into “divided structures of contestation,” or SOCs. In divided SOCs, the monarchy allows only select political opponents to take part in the political system while excluding others. These limited spheres of contestation shape government-opposition relations and dictate the rules of the game for the opposition within the formal political system. The resulting recycling of political parties and coalitions is necessary to maintain the smokescreen of political participation.

In the past, the makhzen has toppled parties wholesale, but this time, the change is more strategic and calibrated. The palace is killing two birds with one stone, removing the source of nuisance without subverting the will of the voters, while forcing change in the PJD’s internal leadership structure.

The Moroccan monarchy has a long tradition of managing opposition parties through co-optation and confinement, allowing opposition parties some stake in power, while the monarchy and the palace shadow government are ultimately in power. In 1997, the USFP won token control of the government. But undermined by the shadow government in the palace, it ultimately lost popular support and bore the brunt of the blame for the country’s socio-economic woes.

If the PJD had opted to leave the government for the opposition, it could have jeopardized its electoral momentum and vision for gradual reforms. But the party’s decision to stay in the government is not without risks either, especially as it seeks to maintain its political standing and appease its rank and file.

As Othmani negotiates with other parties to form the government, it will be interesting to see what course the party charters for him and how much leeway he will have. Remaining in the government under regime’s rules of the game could see the PJD face the same fate as the USFP. While Morocco has passed some nominal reforms in the six years since the Arab uprisings shook the region, this latest incident is a clear reminder of who really wields power in the monarchy.

Mohamed Daadaoui is a professor of political science at Oklahoma City University. He is the author of “Moroccan Monarchy and the Islamist Challenge,” (Palgrave, 2011). You can follow him @Maghreblog.