Kaka scored an injury-time penalty as Brazil survived a huge scare to beat Egypt 4-3 in a thrilling Group B clash at the Confederations Cup in Blomfontein.
The new Real Madrid star placed the ball low to the right of Essam Al-Hadari after substitute Ahmed Al-Muhammadi deliberately handballed Lucio's shot on the line in the final minute of play.
The 2006 and 2008 African champions had staged a remarkable fightback, scoring twice in two second-half minutes to level the game at 3-3.
Kaka had given Brazil a fifth-minute lead with the first of two goals.
Mohamed Zidan levelled soon afterwards but Brazil cruised to a 3-1 half-time lead thanks to goals from Luis Fabiano and Juan.
But a superb second-half performance from the Pharoahs saw them dominate Brazil both with and without the ball.
The introduction of Ahmed Eid put Brazil further on the back foot as Middlesbrough outcast Mohamed Shawky was followed by Dortmund's Zidan in levelling for Egypt within two minutes.
Another sub, Al-Muhamaddi, also impressed wide right but it was his deliberate handball on the goal-line after Lucio met Daniel Alves's corner that led to a red card for the winger and Kaka's 91st-minute winner.
The USA face Italy in the second clash of the group this evening.