OUAGADOUGOU - A shadowy spy master formerly the right-hand man to toppled President Blaise Compaore seized power in Burkina Faso at the head of a military coup on Thursday, less than a month before elections meant to restore democracy in the West African state.

General Gilbert Diendere, who for three decades served as Compaore’s chief military adviser and operated an intelligence network spanning West Africa, was named as the head of a military junta called the National Council for Democracy.

The power grab led by the presidential guard unfolded three days after a government committee recommended dissolving the elite unit, which was a pillar of Compaore’s 27-year rule and has repeatedly meddled in politics since his fall.

A spokesman for the coup leaders hinted at a political agenda to back a return to power by loyalists to Compaore, who has remained in exile in neighbouring Ivory Coast since he was toppled by a popular uprising in October last year.

Under Compaore, Burkina emerged as an important regional ally of France and the United States against al Qaeda-linked militants. It hosts some 200 French special forces as part of France’s Barkhane regional anti-terrorist operation.

The coup sparked condemnation from former colonial power France, the United States and the United Nations. It quashed hopes of a smooth transition in a country that had become a beacon for democratic aspirations in Africa after protesters ousted Compaore when he tried to extend his rule.

Burkina Faso teetered into chaos on Wednesday when the presidential guard arrested interim President Michel Kafando, Prime Minister Yacouba Isaac Zida, and two ministers.

On Thursday, soldiers fired warning shots to disperse a crowd of more than 100 protesters gathered in central Independence Square of the capital Ouagadougou. Soldiers drove the streets in pick-up trucks, beating and detaining demonstrators.

“The patriotic forces, grouped together in the National Council for Democracy, have decided today to put an end to the deviant transitional regime,” said a statement read on state television by Colonel Mahamadou Bamba.

“The transition has progressively distanced itself from the objectives of refounding our democracy,” he said.

Bamba said a change to the electoral law that blocked backers of Compaore from running in the planned Oct. 11 election had “created divisions and frustrations amongst the people”.

His remark hinted that the motivation for the coup was not so much possible dissolution of the presidential guard, but an effort to turn the tables on the democratic transition and return Compaore loyalists to power.

The head of Burkina Faso’s transitional parliament called on the bulk of the armed forces to step in and halt a coup by “a small group” of military officers, and said he would assume leadership until the president was released.

“The transition was put in place by the will of the people, who fixed its duration and its mission...It is not a small group which is going to change that,” Moumina Cheriff Sy told Reuters in an interview. “In the absence of President Kafando, I assume the leadership of the transition.”

The military council announced the closure of land and air borders as well as the implementation of a curfew from 7 p.m. to 6 a.m. It said that senior ministry bureaucrats would carry on the business of government.

A towering figure, nearly 2 metres (6 feet, six inches) tall, Diendere is renowned for his quiet discretion, normally preferring to operate behind the scenes. Under Compaore, he played a central role in negotiating the release of Western hostages seized by Islamist groups in the arid Sahel.

French President Francois Hollande condemned the coup and called for the liberation of those arrested, the restoration of transition authorities and the continuation of the electoral process.

Sporadic gunfire rang out in several districts of the capital early on Thursday morning.

In contrast to October’s uprising when thousands of protesters packed the streets led by civil society groups like Balai Citoyen (Citizen’s Broom), soldiers acted quickly to disperse any groups of demonstrators that formed.

“They asked me if I am part of Balai Citoyen and they beat me with a belt,” said one demonstrator who declined to give his name. “They told me, ‘Now its our turn to play havoc’.”