Algeria's president replaced the North African nation's long-time intelligence chief on Sunday with the former No. 2 of the powerful agency who has most recently served as presidential aide.

Gen. Mohamed Mediene, who served for 25 years as head of the powerful Department of Intelligence and Security, or DRS, was pushed into retirement. The move appeared to be a final step in the president's plan to restructure the services dealing with security and intelligence. The much-feared DRS, akin to the secret services, is the most powerful element in Algeria's intelligence apparatus.

President Abdelaziz Bouteflika "today ended the functions" of Mediene, according to a statement from the president's office. Mediene had served since 1990 as chief of the much feared DRS, and was replaced by Athmane Tartag.

Tartag, a retired general, was No. 2 in the DRS until 2013, when the restructuring began. He was then named as Bouteflika's counselor. The president's statement said only that Tartag had held numerous ranking intelligence and security posts before becoming Bouteflika's aide.

The change of hands was made during a ceremony presided over by armed forces chief Gen. Ahmed Gaid Salah.

The end of the reign of Mediene, known to his countrymen by the nickname "Toufik," also marks the end of an era that, for many observers, was foreseeable despite the opacity within the military establishment that runs Algeria from behind the scenes.

There have been a series of high-level departures over the past two years, including the army's security chief, Gen. Mehana Djebbar, the head of counterespionage, Gen. Hassan, along with changes at the top of the judicial police, the service that oversees the press, and the service charged with economic investigations.

The president's entourage has portrayed the restructuring as a move toward democratizing the system, while some opponents sense a settling of scores.