A last-minute Kaka penalty spared Brazil's blushes as they beat battling Egypt in the Confederations Cup.
Real Madrid's new signing had earlier slotted the opener before Mohamed Zidan headed an equaliser for Egypt.
Brazil's Luis Fabiano and Juan nodded in a goal apiece before half-time, but Egypt scored twice in a minute through Mohamed Shawky and Zidan to level.
Ahmed El Mohamady was sent off for a deliberate handball and Kaka secured victory with a coolly-taken penalty.
Egypt went into the game on the back of a miserable 3-1 defeat by Algeria last week - their biggest margin of defeat in a World Cup qualifier for 32 years - and this loss will be hard to take after they matched Brazil for much of a highly-entertaining clash.
The Brazilians began their title defence by naming a powerful team, with new Real Madrid galactico Kaka playing behind Manchester City's Robinho, and they made a dream start.
Kaka strolled past three Egyptian defenders, controlled the ball on the penalty spot with a delicate touch and slotted home to give Brazil the opener with just five minutes on the clock.
All those thinking that might have opened the floodgates against the African champions were in for a shock just three minutes later when Zidan grabbed the equaliser.
The Borussia Dortmund striker did well to climb above the defence to nod in Mohamed Aboutrika's cross past motionless keeper Julio Cesar.
With 18 goals in their last six internationals Brazil possess plenty of firepower and coach Dunga soon saw his side go ahead again as Luis Fabiano glanced home a header from Elano's whipped-in free-kick.
The lead was further extended before half-time with Juan powering in a magnificent header.
Egypt caught up in Webb of controversy
All seemed comfortable for the South Americans but Egypt had other ideas and Middlesbrough midfielder Shawky orchestrated a phenomenal 60 seconds soon after the break to wipe the smiles off the faces of the Brazilian fans.
With the Brazil defence increasingly being forced backwards Shawky stepped up a gear after some fine build-up play on the left and unleashed a fine shot to give Egypt hope.
Less than a minute later they were all-square as Aboutrika threaded the ball through for Zidan to race ahead and rifle in his second of the game.
The match looked to be heading for a draw but in the final minute eagle-eyed English referee Howard Webb spotted a deliberate handball by Ahmed El Mohamady, who used his arm to stop a shot on the goal line.
The Egyptians were incensed but it was the correct decision and Kaka stepped up to calmly stroke home the penalty and secure a barely deserved win for Brazil.
They will now almost certainly qualify for the second round of a tournament they have won twice, but the team will be wanting an improved effort against the United States on Thursday.
Brazil: Julio Cesar, Dani Alves, Lucio, Juan, Kleber (Andre Santos 83), Felipe Melo, Elano (Ramires 64), Silva, Kaka, Luis Fabiano, Robinho (Alexandre Pato 64). Subs Not Used: Gomes, Maicon, Luisao, Miranda, Julio Baptista, Josue, Kleberson, Nilmar, Victor.
Goals: Kaka 5, Luis Fabiano 12, Juan 37, Kaka 90 pen.
Egypt: El Hadari, Gomaa, Moawad, Said Ahmed, Said, Fathi, Abd Rabou (El Mohamady 76), Shawky, Hassan (Eid 52), Aboutreika, Zidan. Subs Not Used: El Sayed, Abdel-Ghani, Farag, Raouf, Fathallah, Homos, Khairy, Tawfik, Abu Greisha, Sobhy.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.