Algiers - Algerian leader Abdelaziz Bouteflika has replaced his powerful intelligence chief, the presidency announced on Sunday, confirming his domination over the armed forces after a security shake-up.
The presidency said General Mohamed Mediene, dubbed Algeria's "kingmaker", had been replaced by his deputy, General Athmane "Bachir" Tartag, after 25 years as head of the DRS intelligence service.
Bouteflika replaced Mediene "in line with the constitution" and using his prerogatives as president and defence minister, it said in a statement.
The presidency said Mediene had "retired", but provided no further details.
The 76-year-old better known as General Toufik was a powerful man who saw five presidents and a dozen prime ministers come and go, prompting some to call him "rab dzayer" or the "God of Algeria".
Also Read: Young Algerians let their hair down at the mall
Mediene had never appeared in public, but on Sunday his picture was published for the first time by a local newspaper, En-Nahar, showing him in a suit and tie and wearing sunglasses.
Toufik was the last serving general from among a line of top officers behind a crackdown against the radical Islamic Salvation Front (FIS) after it swept to victory in elections in the early 1990s.
The army stepped in to annul the vote, sparking an Islamist insurrection and a brutal civil war that lasted nearly a decade and killed 200 000 people.
During that time, DRS head Mediene became one of the most powerful men in the oil-rich North African state.
His successor General Bachir, an engineer by training, was one of his key deputies during the civil war. He served as a security adviser to Bouteflika from September 2014.
Behind-the-scenes power struggle
The announcement of Mediene's replacement came a day after Bouteflika's chief of staff confirmed the arrest last month of Algeria's former counter-terrorism chief.
Abdelkader Ait-Ouarabi, a close ally of Mediene and better known as General Hassan, had himself previously headed the DRS and was at the centre of the army's fight against Islamists for two decades.
The daily Al-Watan revealed the arrest of General Hassan at the end of August, saying he was detained at his home and taken to Blida military prison, south of Algiers.
General Hassan's arrest came several weeks after the sacking of three security chiefs including two considered close to Mediene - the head of counter-intelligence and the chief of presidential security.
Experts have said the arrest and sackings are part of a behind-the-scenes power struggle between Bouteflika and the powerful DRS.
Analysts say the balance has tilted in favour of the tight circle around Bouteflika and his army chief of staff, Ahmed Gaid Salah, at the expense of a rival faction centred on Mediene.
Political science professor Rachid Tlemcani said: "The battle is coming to an end and President Bouteflika has defeated the shadowy power" - a reference to the DRS.
Echoing many, he described the intelligence service as "a state within a state".
Political analyst Rachid Grim has said "now the presidency has taken power", in an account of Bouteflika's actions.
Armed Islamist groups
Over the past 18 months, the DRS had already lost many of its powers - including the right to carry out judicial probes into graft - and some of its responsibilities have been transferred to the army.
These developments come as Algeria faces a raft of challenges.
More than two decades after the civil war, the army continues to be at the forefront of a campaign against jihadists.
Also Read: Algeria power struggle intensifies with arrest, sackings
Armed Islamist groups are still active in the country, where in 2013 a four-day siege by Islamists of In Amenas gas plant left 38 hostages dead, all but one of them foreigners.
Algeria also faces a financial crisis, compounded by weaker oil prices. The central bank said last week that foreign reserves had fallen 11.1% in the first six months of 2015.
The 78-year-old Bouteflika, who has ruled Algeria since 1999, has the power to sack any security official or force him into retirement.