Burkina's military seized the airwaves and installed a general loyal to the ex-president Thursday as the new head of state, carrying out a coup weeks before national elections.

The developments capped a dramatic year in this West African country where President Blaise Compaore was ousted in a popular uprising last October after he tried to prolong his 27-year rule.

That paved the way for the formation of a transitional government, but soldiers arrested the interim president and prime minister late Wednesday and announced hours later that they had been removed from office.

The political unrest sparked violence in the streets, and the presidential guard opened fire with live ammunition to disperse crowds protesting the coup, witnesses said late Wednesday. Associated Press journalists saw the bodies of at least six victims at a morgue in the capital of Ouagadougou on Thursday.

Members of the presidential guard wandered about the city in pickups and on motorcycles seeking to disperse any gatherings late Thursday.

Burkina Faso's land and air borders were closed and a 7 p.m.-to-6 a.m. curfew was imposed. The coup — the country's sixth since it won independence from France in 1960 — unfolded overnight with stunning speed. Late Wednesday, the country's interim president and prime minister were arrested at the presidency during a ministerial meeting.

A communique read on state TV and radio early Thursday by an army lieutenant colonel wearing a camouflage uniform criticized the electoral code, which blocked members of Compaore's party from taking part in the Oct. 11 elections. Anyone who supported the ex-president's bid to amend the constitution so he could seek another term was also banned from running.

The coup leaders later announced that Gen. Gilbert Diendere, who had been head of the elite presidential guard under Compaore and was his longtime aide, was now in charge of the nation.

In a telephone interview with The Associated Press, Diendere also criticized the electoral code and vowed that elections would go forward — but not on the timeframe that has been set.

"Today it seems to me that the Oct. 11 date is too soon to hold the election," Diendere said. "It's not at our level to speak of Compaore's return. We want to stabilize the country and hold elections."

Compaore and his family initially fled to Ivory Coast but his whereabouts on Thursday were unknown.

Diendere is among African soldiers who have taken part in the U.S.-led Flintlock military exercise. The exercise is held each year to improve African militaries' counter-terrorism efforts. Diendere confirmed to the AP that he had traveled to Chad earlier this year ahead of the exercise.

Photos posted in 2010 by the U.S. military's Africa Command showed Diendere, wearing a red beret, addressing Burkinabe soldiers before their deployment to Mali in support of that year's Flintlock exercise.

U.N. Secretary-General Ban Ki-moon condemned the coup in the strongest terms, and he demanded that all detained officials be released immediately and that the country's political transition resume, his spokesman said in a statement. Ban also said those responsible for the coup and its consequences must be held accountable.

France, the country's former colonial power, the United States and others expressed alarm about the unfolding events.

"The United States strongly condemns any attempt to seize power through extra-constitutional means or resolve internal political disagreements using force," State Department spokesman John Kirby said in a statement.

Speaking on state TV and radio early Thursday, Lt. Col. Mamadou Bamba said the country's transitional government was dissolved and the interim president was no longer in power. He announced the beginning of a "coherent, fair and equitable process" that would lead to inclusive elections.

Burkina Faso hosts French special forces and serves as an important ally of both France and the United States in the fight against Islamic militants in West Africa. While Burkina Faso has largely been spared from extremist violence, a Romanian national was abducted in April, and a Mali-based jihadi group claimed responsibility.