Want smart analysis of the most important news in your inbox every weekday, along with other global reads, interesting ideas and opinions to know? Sign up for the Today’s WorldView newsletter.

In 1963, shortly after Algerians won their independence from France, Abdelaziz Bouteflika, a charismatic veteran of that war, was named the new nation’s first foreign minister — emerging on the international stage in his mid-20s as the youngest person ever to serve as a country’s top diplomat.

On Tuesday, at age 82 and after 20 years in power, Bouteflika stepped down from Algeria’s presidency. After weeks of mass protest, he left office not just as the country’s longest-serving president, but as one of the world’s oldest heads of state.

“Sometimes, history has a sense of humor,” said Dalia Ghanem, an Algerian political analyst and resident scholar at the Carnegie Middle East Center in Beirut.

Over his career, Bouteflika spent nearly 60 years in the public eye, developing a complicated legacy that saw him alternately lauded as a progressive anti-colonialist, exiled for corruption, welcomed home as a peacemaker and, eventually, forced from power after overstaying his welcome.

At 19, he joined the Algerian independence movement and served in the National Liberation Army (ALN). Politically wise, even at such a young age, Bouteflika rose quickly, becoming a close associate of military officer Houari Boumédiène, who would one day become Algeria’s second president. Such alliances would serve him well in the following decades.

Bouteflika was a member of Algeria’s first constitutional assembly and served as a delegate in the country’s first and second legislative bodies. In 1962, he was appointed minister of youth, sports and tourism, and then promoted to foreign minister less than a year later.

As Algeria’s first foreign minister post-independence, Bouteflika had a reputation as a young, capable diplomat who sought to modernize the North African country and solidify its international prominence in the aftermath of French rule.

He led negotiations with the French to resolve issues that lingered after independence, including the complicated settlement over Algeria’s petroleum industry, the young nation’s lifeblood. As foreign minister, he served as Algeria’s representative to the United Nations. As president of the U.N. General Assembly in 1974, he famously invited Palestinian leader Yasser Arafat to speak in New York.

But he fell from grace following Boumédiène’s death in 1978. He was once thought to be Boumédiène’s natural successor as president, but the military backed Defense Minister Chadli Bendjedid. After Bouteflika became mired in a corruption scandal — charges he claimed were political — he went into self-imposed exile in 1981.

He returned home in 1987 and started to rebuild his political standing, and in 1999, he managed to win the presidency. He took office as Algeria sought to put an end to one of its darkest periods — a deadly civil war between Algeria and Islamist rebels that may have killed as many as 200,000 Algerians.

As president, Bouteflika oversaw a reconciliation program as the country recovered from what is now known as its “black decade.” There was controversy over some aspects of reconciliation between the Algerian government and the Islamists, particularly among families of victims who felt the rebels were let off easy. Others were happy to find a way to move on.

Ghanem, the political analyst, told Today’s Worldview that the country was immensely scarred by the brutality of the conflict. Bouteflika, she said, “was the architect of peace, but also the president who brought back Algeria to the international arena after more than 10 years of total diplomatic isolation. And for that, Algerians loved him.”

“Unfortunately, he didn’t know when to stop,” she said.

In 2004, he was elected to a second term, winning 85 percent of the vote. His popularity allowed him to exert more control, and the constitution was amended, lifting presidential term limits. In the future, many in Algeria may remember him as he is now: an elderly man in a wheelchair, left disabled by a stroke in 2013.

As Bouteflika “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,” my colleague Sudarsan Raghavan reported this week.

He solidified his power by surrounding himself with allies, many of whom, like him, were veterans of the fight for Algeria’s independence.

The aging Bouteflika began to disappear from public life after suffering a stroke, but he clung to power. Observers were acutely aware that Bouteflika’s inner circle was helping to run the show — and earlier this year, when he announced he would seek a fifth term in office, many Algerians felt they had seen enough.

Protesters took to the streets to demand he step down. He attempted to placate the public, offering a government reshuffle and walking back his bid for reelection. But for those who had risen up against him, those promises didn’t go far enough. As protests continued unabated, “the embattled leader watched as many of his most powerful allies abandoned him,” Raghavan wrote.

Algeria’s top military officials were among those who called for him to step down. “Our decision is clear and irrevocable,” said Gen. Ahmed Gaid Salah, the vice defense minister and army chief of staff. “We will support the people until their demands are fully and completely satisfied.”

On Tuesday, Algeria’s state news agency announced Bouteflika had resigned.

After so long at Algeria’s helm, it is unfortunate, Ghanem said, that “he hasn’t been able to say goodbye to power in a more graceful way.”

Want smart analysis of the most important news in your inbox every weekday, along with other global reads, interesting ideas and opinions to know? Sign up for the Today’s WorldView newsletter.