Brazil tonk Tanzania in warm-up
Midfielder Ramires added the other two goals, his first for Brazil.
Kaka, who suffered niggling injuries in a frustrating first season at Real Madrid, netted his first international goal in nearly a year.
He played the full 90 minutes and produced several characteristic bursts from midfield in an encouraging performance.
Tanzania's goal deprived Brazil of a sixth successive clean sheet. The last team to score against the five-times world champions was Bolivia in October.
"I feel good but I still need to let myself go a little," Kaka told Brazilian television.
The visitors were without Julio Cesar in their starting line-up for the first time in two years.
The Inter Milan goalkeeper was left out as a precaution after hurting his back in a 3-0 win over Zimbabwe.
Brazil went ahead after 10 minutes when Kaka set up Robinho to score with an angled shot.
The hosts created a couple of chances but Brazil rode the storm and made it 2-0 when Robinho tapped in from close range after a cross from Michel Bastos went across the face of the goal.
Brazil, who face North Korea, Ivory Coast and Portugal in their first-round group, extended their lead eight minutes after the restart when Ramires burst down the left to score.
Kaka added the fourth, scoring with his chest from Maicon's cross in the 76th minute, before Tanzania notched a consolation effort 10 minutes later as Jabir Aziz headed in from close range.
Ramires made it 5-1 by nodding in a Daniel Alves cross in injury time.