CAIRO Mediating the Gaza truce was a bravura diplomatic performance by Egypt's new President Mohamed Mursi, jacking up his personal stature and reassuring an anxious Washington that the architecture of Middle East peace can survive the Arab Spring.
For nearly two years, Washington has fretted over what would happen in a major showdown between Israel and the Palestinians without the Arab autocrats that kept stability for decades, above all Egypt's Hosni Mubarak who presented himself as the personal guarantor of its 1979 peace with Israel.
Mubarak was toppled by a popular revolt last year, and his successor Mursi hails from the Muslim Brotherhood, an Islamist group whose rise Washington has feared for decades.
But by keeping the trust of Israel and the United States, and using his own Muslim Brotherhood background to develop a rapport with Gaza's ruling Hamas militants, Mursi has passed the test of his first Israel-Palestine crisis with flying colors.
"Everyone is pointing to Mursi as a winner in this and as a crucial player," said Shadi Hamid of the Brookings Doha Center. "He comes out of this with more political capital on the regional and international front."
Praise from Washington has come fast and thick.
"I want to thank President Mursi for his personal leadership to de-escalate the situation in Gaza and end the violence," said U.S. Secretary of State Hillary Clinton, who spent Wednesday at Mursi's palace being briefed on the negotiations by his staff.
The achievement is especially extraordinary for a 61-year-old engineer once mocked as the "spare tyre" because he was selected as the Brotherhood's presidential candidate only after its first choice was barred from standing by a court.
The truce, which ended a week of Israeli bombing of Gaza and Hamas rocket attacks on Israel, allows Mursi to put his stamp on Palestinian-Israeli policy still largely run by the intelligence and security services that were Mubarak's personal fiefs.
Mursi has been steadily expanding his authority over the Arab world's biggest nation since he defeated an army-backed candidate five months ago. A quietly sure-footed performance on the world stage regained for Egypt some of the influence many felt was lost as Mubarak, now 83, aged in office.
He still has a huge in-tray: there is no permanent constitution, he has no parliament, the economy is on the ropes and many in the security establishment remain suspicious of their new Islamist leader.
During the crisis, some Egyptians complained he was not focused on problems at home.
As bombs fell in Gaza, a train ploughed into a school bus killing 51 people, most of them children, and the government reached an initial deal for a $4.8 billion loan from the International Monetary Fund linked to unpopular reforms.
But the success in negotiating the Gaza truce makes some of those problems recede for now, giving him time and authority to tackle other problems.
Winning over a sceptical Washington has been a hard slog. The United States, which gives Egypt's military $1.3 billion a year, opened formal channels to the Muslim Brotherhood only in mid-2011, several months after Mubarak's overthrow.
During his election campaign, President Barack Obama described Egypt as neither a friend nor an enemy of Egypt, remarks that one diplomat said were taken in Cairo as a surprising snub.
But throughout the days of the Gaza crisis, Mursi was in regular telephone contact with Obama.
"Whatever the relationship was a week ago, it's clearly better now," said Jon Alterman, director of the Middle East programme at the Center for Strategic and International Studies think tank in Washington.
On Wednesday Clinton spent much of the day behind the marble walls of Mursi's presidential palace, being updated by officials mostly picked out from ranks of the Brotherhood, who relayed details from the headquarters of the intelligence service hosting the Palestinian delegation to the deal talks.
Mursi aides say the president has been seeking a date to meet Obama and the Gaza deal might bring that forward.
He and Obama will not see eye to eye on everything: the Brotherhood still describes Israel as a racist and expansionist state. Mursi's trick is to show that holding those views does not necessarily mean repudiating the 1979 Egypt-Israel treaty, or disavowing a relationship with the United States, particularly important at a time when the economy is so weak.
A SHIFT BUT NOT AWAY
"It is important to have a strong relationship with the United States, but such a relationship will be different than in Mubarak's time when Egypt used to be a follower. Now it is a partnership based on mutual interests," said Murad Mohamed Ali, a leader in the Brotherhood's Freedom and Justice Party and one of the spokesmen for Mursi's presidential campaign.
It is a theme repeated by Mursi aides, who long before the crisis spoke of rebalancing Egyptian policy while keeping U.S. ties solid. "A shift does not mean a shift away," said one.
The approach reflects a pragmatic streak that runs through the Brotherhood and has been soaked up by Mursi, who spent several years studying and teaching in California.
The Gaza deal will help Mursi gain more authority over the intelligence service, still packed with Mubarak-era officials many of whom have difficulty disguising their disdain for the their new Islamist leader.
Though Mursi's role was recognised by negotiators as playing an important role in the deal, state media headlined the deal as a success for the veterans in the intelligence service.
"The current leadership is civilian and lacks the information or security sense to give Palestinians advice on what is really going on," said one intelligence source close to the Gaza talks who declined to be named. Mursi offered "warm religious rhetoric" to Hamas instead, he said dismissively.
But another security source close to the negotiations acknowledged that Mursi's rapport with Hamas had played an important role.
Speaking as the talks were in the final hours, he said: "I could see Hamas was more comfortable with us after President Mursi came (to power) and trusts Egypt and our suggestions more."
The unfinished business of winning control over the security establishment remains a major task for the president, who weeks into office sacked the intelligence chief after 16 Egyptian border guards were killed, and then swiftly pushed aside the top generals in the army.
"If Mursi keeps on coming up with victories like this (in Gaza) he will be able to stake a greater claim on the foreign policy apparatus," said Hamid of the Brookings Institute.
"It is still going to be a slow process. But this is going to help shift the balance at least a little bit."
(Additional reporting by Yasmine Saleh and Marwa Awad in Cairo and Arshad Mohammed in Washington; writing by Edmund Blair; editing by Peter Graff)