CAIRO In Hosni Mubarak's final days in office in 2011, the world's gaze focused on Cairo, where hundreds of thousands of protesters demanded the resignation of one of the Arab world's longest serving autocrats.
Little attention was paid when a group of Muslim Brotherhood leaders broke free from their cells in a prison in the far off Wadi el-Natroun desert. But the incident, which triggered a series of prison breaks by members of the Islamist group around the country, caused panic among police officers fast losing their grip on Egypt.
One officer pleaded with his comrades for help as his police station was torched. "I am faced with more than 2,000 people and I am dealing with them alone in Dar al Salam, please hurry," the policeman radioed to colleagues as trouble spread. "Now they have machine guns, the youth are firing machine guns at me, send me reinforcements."
In all, 200 policemen and security officers were killed that day, Jan 28, called the Friday of Rage by anti-Mubarak demonstrators. Some had their throats slit. One of the Muslim Brotherhood leaders to escape was Mohamed Mursi, who would become president the following year.
Egypt's Interior Ministry, which controls all of the country's police forces including state security and riot police, never forgot the chaos. In particular the Wadi el-Natroun prison break became a powerful symbol inside the security apparatus of its lost power. Officers swore revenge on the Brotherhood and Mursi, according to security officials.
When army chief Abdel Fattah al-Sisi appeared on television in July this year to announce the end of Mursi's presidency and plans for elections, it was widely assumed that Egypt's military leaders were the prime movers behind the country's counter revolution. But dozens of interviews with officials from the army, state security and police, as well as diplomats and politicians, show the Interior Ministry was the key force behind removing Egypt's first democratically elected president.
Senior officials in Egypt's General Intelligence Service (GIS) identified young activists unhappy with Mursi's rule, according to four Interior Ministry sources, who like most people interviewed for this story, asked to remain anonymous. The intelligence officials met with the activists, who told them they thought the army and Interior Ministry were "handing the country to the Brotherhood."
The intelligence officials advised the activists to take to the streets and challenge Mursi, who many felt had given himself sweeping powers and was mismanaging the economy, allegations he has denied. Six weeks later, a youth movement called Tamarud - "rebellion" in Arabic - began a petition calling for Mursi to step down.
Though that group's leaders were not among the youth who met the intelligence officials, they enjoyed the support of the Interior Ministry, according to the Interior Ministry sources. Ministry officials and police officers helped collect signatures for the petition, helped distribute the petitions, signed the petition themselves, and joined the protests.
"They are Egyptians like us and we were all upset by the Brotherhood and their horrible rule," said a 23-year-old woman in the Tamarud movement who asked not to be named.
For the Interior Ministry, Tamarud offered a chance to avenge Wadi el-Natroun; the reversal of fortunes has been remarkable. The state security force, both feared and despised during Mubarak's 30-year rule, has not only regained control of the country two and half years after losing power, but has won broad public support by staging one of the fiercest crackdowns on the Muslim Brotherhood in years.
The interior minister openly speaks of restoring the kind of security seen under Mubarak. A renewed confidence permeates the police force, whose reputation for brutality helped fuel the 2011 uprising. Egyptians now lionise the police. Television stations praise the Interior Ministry and the army, depicting them as heroes and saviours of the country.
The Interior Ministry's most dreaded unit, the Political Security Unit, has been revived to deal with the Brotherhood. Under Mubarak, officers in that department were notorious for treating citizens with a heavy hand and intruding into their lives. When activists broke into the agency's premises shortly after Mubarak was forced to quit on February 11, 2011, they found and posted online documents, videos and pictures of what they described as a torture chamber with a blood-stained floor and equipped with chains.
The Interior Ministry has apologised for "violations" in the past and has said they will not be repeated.
Key to the turnaround has been the Interior Ministry's ability to forge much closer ties to the army, the most powerful and respected institution in Egypt. It was a tactic that began almost as soon as Mubarak stepped down.
Weeks after Mubarak was overthrown, the Interior Ministry called a meeting at the police academy in Cairo. The gathering, headed by the interior minister and senior security officials, was the first in a series that discussed how to handle the Brotherhood, according to two policemen who attended some of the gatherings.
Thousands of mid- and lower-ranking officers were angry and said they could not serve under a president they regarded as a terrorist. Senior officers tried to calm them, arguing that the men needed to wait for the right moment to move against Mursi. "We tried to reassure them but the message did not get through," said a senior police official. "They just fumed silently."
The senior state security officer told Reuters there were no explicit orders to disobey Mursi but that a large number of officers decided they would not be "tools" for the Brotherhood.
"I worked during Mursi's time. I never failed to show up at any mission. This included securing his convoys. Yet I never felt I was doing it from the heart," said one major in state security.
"It was hard to feel that you are doing a national job for your country while what you are really doing was securing a terrorist."
Resentment grew when Mursi pardoned 17 Islamist militants held since the 1990s for attacks on soldiers and policemen. One of the militants had killed dozens of policemen in an attack in the Sinai. None of them publicly denied the charges or even commented on them.
Mursi's decision last November to grant himself sweeping powers triggered a wave of public protest. On December 5, protesters rallied in front of the Ittihadiya, the main presidential palace in Cairo. As the crowd grew, Mursi ordered security forces to disperse them. They refused. A senior security officer said there was no explicit order to disobey Mursi but they all acted "according to their conscience."
The Muslim Brotherhood brought in its own forces to try and quell the unrest and Brotherhood supporters tried to hand some protesters to police to be arrested. But the police refused, Brotherhood officials said at the time.
"Do they think the police forgot? Our colleagues are in jail because of the Brotherhood," said a state security officer.
Ten people were killed in the ensuing clashes, most of them Brotherhood supporters. Liberal activists accused Brotherhood members of beating and torturing anti-Mursi protesters.
Mursi miscalculated further by calling off a meeting sought by the army to discuss how to calm the storm, according to two army sources.
"It was a veiled message to stay out of politics, and we got it, as we understood that Mursi was an elected leader and (it) would be hard to defy that," said an army colonel. "But it was clear by then where his rule was driving the state."
In January 2013, Mursi fired Ahmed Gamal, former senior state security officer, as interior minister and replaced him with Mohamed Ibrahim who was the senior-most official with the least exposure to the anti-Brotherhood factions inside the ministry, security sources said. Ibrahim was seen as weaker and more malleable than Gamal, who was blamed by the Brotherhood for not acting harshly enough against anti-Mursi protests.
But appointing Ibrahim, who was previously an assistant to the interior minister for prison affairs, proved to be a costly mistake. He moved to get close to the army, attending events to establish direct contact with army chief Sisi and regularly complimenting the general on his management techniques, said the police major.
Sisi had served as head of military intelligence under Mubarak. He was known to be religious and had the charisma to inspire younger army officers. Mursi believed those younger officers posed less of a threat than the old generals who had served under Mubarak and whom he fired in August 2012, two months after he took office.
But the country's police chiefs had one message for the military: The Brotherhood is bad news.
"We are in constant fights on the streets. This made us tougher than the army and ruthless," said the police major. "We don't understand the language of negotiating with terrorists. We wanted to handle them from day one."
Ibrahim rejected requests by Reuters for an interview and would not answer questions sent by email. Sisi could not be reached for comment.
By early 2013, army officers and Interior Ministry officials had begun meeting in the military's lavish social and sports clubs, some of which overlook the Nile. Over lunch or steak dinners, officials would discuss the Brotherhood and Egypt's future, according to senior state security officers and army officers who took part in the meetings.
The Interior Ministry argued that the Brotherhood was a threat to national security and had to go, according to one senior security officer. In the 1990s, during the Interior Ministry's battle with the Muslim Brotherhood, the ministry had referred to all Islamists as terrorists. It urged the army to adopt the same terminology.
"I have gone to some of those meetings with the army and we spoke a lot about the Muslim Brotherhood. We had more experience with them then the army. We shared those experiences and the army became more and more convinced that those people have to go and are bad for Egypt," the senior security officer said.
"The army like many people who have not dealt directly with the Brotherhood and seen their dirtiness wanted to believe that they have something to offer to Egypt. But for us it was a waste of time."
Officials in the Interior Ministry warned the military that Mursi's manoeuvrings were merely a way to shore up his power. The Muslim Brotherhood, they told their army colleagues, was more interested in creating an Islamic caliphate across the region than serving Egypt.
"The Brotherhood have a problem with the Egyptian state," said the state security officer. "I am certain that Mursi came to implement the plan of the Brotherhood ... They don't believe in the nation of Egypt to begin with."
Over time, middle-ranking Interior Ministry officers became more vocal with the military. The message got through at the highest level. Early this year, army chief Sisi warned Mursi that his government would not last.
"I told Mursi in February you failed and your project is finished," Sisi was quoted as saying in an interview published this month in the newspaper al-Masry al-Youm.
Interior Ministry officials believed that the Brotherhood planned to restructure the ministry, one state security officer said. Concerned officials discussed the issue in a private meeting in the parliament. One option was the cancellation of the police academy. Many saw that as a threat to their institution and careers.
"The news became known to young officers. This action is against the interest of the officers. He was fighting their future," said the state security officer.
Muslim Brotherhood officials have denied plotting against the Interior Ministry and say there were no plans to dismantle the police academy. They have previously accused Interior Ministry officials of working to undermine the government, refusing to protect Brotherhood leaders, and trying to turn the public against the group's rule.
"We cooperated with the Interior Ministry all along. We never had plans to undermine it or the police academy. It was the Interior Ministry that refused to work with us," said Brotherhood official Kamal Fahim. "All along they resisted us and tried to turn Egyptians against us."
Pressure from the Interior Ministry on Sisi and the military grew, helped by the emergence in May of the Tamarud.
At first the group was not taken seriously. But as it gathered signatures, Egyptians who had lost faith in Mursi took notice, including Interior Ministry officials. Some of those officials and police officers helped collect signatures and joined the protests.
"Of course we joined and helped the movement, as we are Egyptians like them and everyone else. Everyone saw that the whole Mursi phenomena is not working for Egypt and everyone from his place did what they can to remove this man and group," said a security official.
"The only difference was that the police and state security saw the end right from the start but the rest of the Egyptians did not and had to experience one year of their failed rule to agree with us."
On June 15, the Interior Ministry held a meeting of 3,000 officers, including generals and lieutenants, at its social club in the Medinat Nasr district of Cairo to discuss the death of a police officer killed by militants in Sinai. Islamist militancy in Sinai, mainly targeting police and army officers, had risen sharply after Mursi's election.
Some at the meeting blamed "terrorist elements ... released by Mohamed Mursi," said the state security officer.
Police officers started chanting "Down, down with the rule of the General Guide," a reference to Muslim Brotherhood General Guide Mohamed Badie, now in jail on charges of inciting violence during the Ittihadiya protests.
On June 30 - the anniversary of Mursi's first year in office - angry Interior Ministry officers joined Tamarud members and millions of other Egyptians to demand the president's resignation. Four days later, Sisi appeared on television and announced what amounted to a military takeover. Some security officials called the move "the revolution of the state."
TEARGAS, BULLETS AND BULLDOZERS
For weeks after Mursi's overthrow, Western officials tried to persuade Sisi to refrain from using force to break up Brotherhood protest camps in Cairo. But the hardline Interior Ministry, which had quickly regained its old swagger, pressed for a crackdown. Police officials argued that Brotherhood members had weapons.
"For us, negotiations were a waste of time," said the state security major. "We know what was coming: terrorism. And now after this horrible experience I think everyone learned a lesson and appreciates us and that we were right about those people."
Early on the morning of August 14 policemen in black uniforms and hoods stormed the Rabaa al-Adawiya camp, one of two main vigils of Brotherhood supporters in Cairo.
The police ignored a plan by the army-backed cabinet to issue warnings and use water cannons to disperse protesters, instead using teargas, bullets and bulldozers. Hundreds died there and many more died in clashes that erupted across the country after the raid.
Army officers later asked the police why the death toll was so high, according to a military source. The interior minister said his forces were fired on first.
"It is one thing for decisions to be taken by officials in suits and sitting in air-conditioned rooms," said a state security officer in charge of some top Brotherhood cases. "But we as troops on the ground knew that this decision can never be implemented when dealing with anything related to this terrorist organisation. Force had to be used and that can never be avoided with those people."
Despite the use of force and the deaths, liberal Egyptians who had risen up against Mubarak seemed sanguine.
The liberal National Salvation Front (NSF) alliance praised the actions of security forces. "Today Egypt raised its head up high," said the NSF in a statement after the raid. "The National Salvation Front salutes the police and army forces."
Two years after the Wadi el-Natroun prison break, the Interior Ministry had power again. It announced it would use live ammunition when dealing with protesters it accused of "scaring citizens." Trucks used by the once-dreaded anti-riot security forces now have signs on them which read "The People's Police."
The government has jailed the Brotherhood's top leaders in a bid to crush Egypt's oldest Islamist movement. Muslim Brotherhood officials now face trial in connection with the Ittihadiya protests.
Senior security officers say their suspicions about the Brotherhood were confirmed in documents they found when they raided the group's headquarters. The documents suggested that Mursi planned to dismantle the army under the guise of restructuring, they said. One of the documents, which a state security officer showed to Reuters, calls for the building of an Islamic state "in any eligible spot."
Muslim Brotherhood leaders could not be reached to comment on this document because most of them are either in jail or hiding.
Police officials say they no longer abuse Egyptians and have learned from their mistakes under Mubarak. But not everyone is buying that line.
Muslim Brotherhood leader Murad Ali, who was recently imprisoned, wrote in a letter smuggled out of prison and seen by Reuters that he was put in a foul-smelling, darkened cell on death row and forced to sleep on a concrete floor. Lawyers for other Brotherhood members say prisoners are crammed into small cells and face psychological abuse. One elderly Brotherhood prisoner said guards shaved his head and brought vicious dogs around to scare him, inmates near his cell told Reuters.
There were no complaints of the type of whipping or electrocution seen in Mubarak's days. But Brotherhood members say the current crackdown is more intense. "The pressure never subsides. None of my Brotherhood colleagues sleep at the same place for too long and neither do I," said Waleed Ali, a lawyer who acts for the Brotherhood.
(The story is refiled to clarify in paragraph 7 that GIS is not part of Interior Ministry)
(Writing by Michael Georgy; Edited by Richard Woods and Simon Robinson)