CAIRO — Algerian President Abdelaziz Bouteflika submitted his resignation Tuesday night, ending his two-decade rule following weeks of massive demonstrations against his continued political aspirations, the state news agency reported.

By late Tuesday night, the squares of the capital, Algiers, were thick with Algerians celebrating the end of Bouteflika’s rule, according to videos and photos posted on social media. Many waved Algerian flags or draped themselves in them. Others honked car horns and danced in the streets, taking selfies to remember this moment.

The announcement was expected but nevertheless represents a stunning turn for the North African nation, which joins the ranks of Egypt, Tunisia, Libya and Yemen, where autocrats have been pushed out of power by popular pressure in recent years.

The ailing Bouteflika, who is 82 and uses a wheelchair, has rarely been seen in public since suffering a stroke in 2013.

Over the past six weeks of large demonstrations, the embattled leader watched as many of his most powerful allies abandoned him. Hours before his resignation, the country’s army chief issued an extraordinarily blunt statement demanding that the president leave office immediately.

Bouteflika’s resignation came a day after his office announced on state media that he would step down before April 28. That short statement also said that Bouteflika would take steps to “ensure state institutions continue to function during the transition period.”

That statement, which offered few details, heightened concerns among many Algerians that Bouteflika was seeking to anoint a handpicked successor, remain politically active behind the scenes and ensure that his clique stayed in control of the country. Students on Tuesday took the streets in protests.

After weeks of protests, Algerian President Abdelaziz Bouteflika’s office announced April 1 he will end his 20-year rule before his mandate ends April 28. (Reuters)

Within Algeria’s powerful military establishment, there was also concern. Earlier on Tuesday, the vice defense minister and army chief of staff, Gen. Ahmed Gaid Salah, held a meeting with senior officials of the Ministry of National Defense and top commanders. He proposed applying articles in the constitution to declare Boute­flika unfit and remove him from office.

“Our decision is clear and irrevocable,” Salah said, demanding that Bouteflika vacate office immediately. “We will support the people until their demands are fully and completely satisfied.”

Salah added that “there is no longer need to waste further time” and that the constitutional measures to unseat Bouteflika should be undertaken immediately. Those remarks sharply increased pressure on the president to step down. On Tuesday, he officially notified the president of the country’s Constitutional Council of his decision to step down, said the state news agency.

Bouteflika, the longest-serving head of state in Algeria, has ruled since 1999. He surrounded himself with a powerful circle of fellow veterans of Algeria’s war for independence from France, as well as business tycoons, military commanders and influential clan members. Together, they are, to this day, known as “le pouvoir” — the Power.

Bouteflika oversaw the end of Algeria’s decade-long civil war against Islamists in which as many as 200,000 people died, bringing him popularity among the people. But as he remained in power, official corruption grew, and Algeria’s economy, dependent on natural gas, suffered from low global prices. Cracks began to appear in his rule.

Demonstrations against him occurred previously, but those were put down by the security and intelligence forces. So when tens of thousands of Algerians swept into the streets in February, opposing Bouteflika’s decision to seek a fifth term in office, few expected him to fall.

But in the end, the security forces, while firing tear gas to disperse protesters, did not resort to a violent crackdown.

Bouteflika initially postponed elections scheduled for this month and carried out a political shake-up. And he promised to undertake political and economic reforms. But throngs of Algerians kept pouring into the streets, declaring that he was seeking to extend his fourth term. They demanded his immediate resignation.

By then, influential allies of Bouteflika, including judges, businessmen and lawmakers, joined the demonstrators. But the most significant defection came last week when Salah, the head of the military, first proposed declaring Bouteflika unfit for office. It was now clear that Bouteflika’s key backers viewed his departure as vital to resolving the country’s biggest political crisis in decades.

Over the weekend, Bouteflika’s office announced a major reshuffling of the government posts and arrested several leading businessmen accused of corruption or seized their passports, moves that many viewed as an effort to calm the tensions on the street.

Significantly, Salah retained his position, an indication of his power. And on Tuesday, he wielded it again, ultimately bringing an end to Bouteflika’s reign.

According to the country’s constitution, the head of the upper house of Parliament, Abdelkader Bensalah, will become interim leader for no longer than three months until an election can be held.

It remains to be seen how the protesters will react. Many said they are seeking not only the removal of Bouteflika but also of his powerful clique. Bensalah, for instance, is widely seen as an ally of Bouteflika.

Protesters have already expressed opposition to a government-led transition under the procedures outlined by the constitution, instead demanding a complete “democratic” transition.

One tweet on Tuesday depicted two messages: The first read: “The First Day of the rest of the Algerian Life.” And the second: “The System is the Next.”

“Bouteflika’s resignation shows how completely he was abandoned by his erstwhile allies and pillars of the government, but this is only the beginning of an uncertain political process,” said Andrew Lebovich, a North Africa and Middle East expert with the European Council on Foreign Relations. “I think protesters will demand much broader changes now that Bouteflika is gone, but we don’t yet know what form this will take.”