Algerian President Abdelaziz Bouteflika stepped down on Tuesday after 20 years in office, and six weeks of massive nationwide protests aimed at pushing him and his much-criticized inner circle from power to create a real democracy in the gas-rich nation.

The announcement followed soon after a sternly-worded call from the powerful army chief for Bouteflika, 82 and ailing, to "immediately" bow out.

Crowds celebrated peacefully in the capital Algiers soon after his announcement. Honking car horns, singing songs and waving Algerian flags, hundreds gathered Tuesday night at the central post office — a plaza that has become a symbol of the protest movement. Police watched from the sidelines.

The Constitutional Council was expected to convene Wednesday to formalize his departure. Under the constitution, the president of the upper house, the Council of Nations, steps in as interim leader for a maximum of 90 days so that elections can be organized.

The current upper house president is Abdelkader Bensalah, a Bouteflika ally — and it's unclear whether protesters will abandon their fight for an overhaul of the entire power structure.

An official in the president's office told The Associated Press that Bouteflika had resigned, and the official APS news agency said in a full-page headline that Bouteflika had notified the Constitutional Council of his decision.

The move came a day after Bouteflika's office said he would leave by April 28, the official end of his fourth mandate — but only after "important" changes were made to ensure institutional continuity. That gave rise to fears that his entourage would do all to preserve the interests of those who profited from his time in office.

There was no word about what would happen to the presidential entourage, including younger brother Said Bouteflika, a top counselor blamed by protesters for widespread corruption in the North African country with a high unemployment rate and a drastic gap between the rich and poor.

Earlier Tuesday, military chief of staff Gen. Ahmed Gaid Salah convened a meeting of the top military hierarchy. That made clear that the army chief's call for Bouteflika to desist had the backing of the military — among the most important on the African continent.

In a communique, the Defense Ministry referred to Bouteflika's entourage as a "gang" and said it had made "fraud, embezzlement and duplicity its vocation."

Bouteflika has rarely been seen in public since a 2013 stroke.

His resignation caps six weeks of peaceful marches by protesters who wanted not just Bouteflika but the entire system to make an exit.

As the protests escalated, Bouteflika announced two new governments and army chief Gaid Salah urged Bouteflika to submit to Article 102 of the Constitution, which would declare him unfit for office. Gaid Salah also called for the application of two more articles championed by protesters, notably Article 7, which stipulates that "the people are the source of power."

Tensions had been mounting in recent days between the army chief and the president's entourage — along with suspicions of a potential military coup.

The Defense Ministry statement Tuesday appeared to be a final warning and the catalyst for Bouteflika's resignation.

Bouteflika was an independence fighter during Algeria's war against colonizer France in the 1950s and 1960s and then went on to defend Third World interests at the height of the Cold War as Algeria's foreign minister.

Bouteflika came to the presidency after Algeria's darkest period, the 1990s Islamic insurgency that left around 200,000 people dead. After taking power in 1999, Bouteflika managed to bring back stability to a country devastated by killings and distrust.

The insurgency then linked up with Al Qaeda and metastasized into a Sahara-wide extremist movement.

As president, however, age and illness took its toll, and corruption scandals dogged Bouteflika and associates.

CLICK HERE TO GET THE FOX NEWS APP

Bouteflika also failed to create an economy that could offer enough jobs for Algeria's growing youth population despite the nation's vast oil and gas wealth.

In a country where secrecy surrounds the leadership, it has never been clear whether Bouteflika was fully in charge or whether the powerful army was pulling the strings.