Kaka came off the bench after six weeks out injured and produced a clinical finish from Cristiano Ronaldo's assist to keep Real Madrid hot on the heels of leaders Barcelona in La Liga on Saturday.
Substitute Raul put Real ahead after 50 minutes and in a heated atmosphere at Zaragoza's Romareda stadium the home side had defender Matteo Contini sent off soon after following a clash with Argentina striker Gonzalo Higuain.
Promoted Zaragoza, two points above the relegation places in 16th, fought back to level at 1-1 through Adrian Colunga in the 62nd minute before Kaka saved the day for big-spending Real.
The result lifted Manuel Pellegrini's side to 86 points with four matches remaining, one behind Barca.
Kaka, who replaced Fernando Gago with 15 minutes remaining, has been sidelined with a lingering groin problem.
His extended absence has led to accusations he lacks commitment to the team he joined from AC Milan for about 67 million euros ($90 million) in the close season.
"The best thing I can do is answer (my critics) on the pitch," Kaka, who will be key to Brazil's bid for glory in South Africa, said in a post-match TV interview.
"I ask the Real Madrid fans to believe in my injury," he added. "I am not hurt (by the criticism), I know that things are like that in football."
FLARING TEMPERS
Barca face the formidable task of overturning a 3-1 deficit in their Champions League semi-final second leg at home to Inter Milan on Wednesday and Pep Guardiola left top scorer Lionel Messi and several other regulars out of his starting lineup.
The hosts were cruising when Jeffren and Henry put them 2-0 ahead after 24 minutes but a fine strike from Mario Bermejo a minute later and sustained Xerez pressure at the start of the second half shook the home fans.
The introduction of Messi and Spain defender Gerard Pique in the 52nd minute appeared to settle Barca down and Ibrahimovic sidefooted home from close range four minutes later to make it 3-1 after good work from Yaya Toure.
It was hardly the performance Guardiola would have wanted as a warm-up for the Inter match but his players were able to defend their two-goal lead reasonably comfortably against a feisty Xerez side.
Tempers flared towards the end and Xerez pair Matias Alustiza and Fabian Orellana were sent off.
Barca have a potentially crucial match at in-form Villarreal next Saturday in a week that could make or break their domestic and European campaigns.
Fans were nonetheless in relaxed mood, with children having their faces painted in the club colours and taking rides on a mechanical Catalan donkey outside the giant arena.
"We wanted to play this match and get it out of the way as soon as possible," Guardiola said at a news conference.
"The team responded very well even though it cost us quite a bit of effort," he added. "It was potentially a very dangerous game for us today and we did what we had to do."
NIGGLING FOULS
Madrid started full of purpose at the Romareda but lost their way when Netherlands midfielder Rafael van der Vaart went off injured after only 15 minutes to be replaced by Raul.
Zaragoza muscled their way back into the game, drawing the visitors into a tit-for-tat succession of niggling fouls and late tackles which boiled over in the 52nd minute, just after Raul had put Real ahead.
Contini swung an elbow, catching Higuain in the chest as the two challenged for the ball, and the Argentine's theatrical fall to the ground clutching his face helped draw a red card.
Colunga blew the game wide open, sprinting clear on a counter attack to round Iker Casillas and level the scores.
Sergio Ramos headed against a post but it was Kaka who saved the day. He burst into the area on to Ronaldo's clever flick and scored a goal that may help restore his tarnished image with unconvinced Madrid fans.
La Liga: Barca thrash Depor 3-0, extend lead
Real Madrid win thriller, go top of La Liga
Ronaldo, Kaka on FIFA's world player shortlist
Xerez stun Villarreal, Atletico slump
La Liga: Barca beat Osasuna 2-0, surge to top spot