Lula said that as a Catholic, he deeply regretted the archbishop's "conservative attitude".
"It is not possible to allow a little girl raped by her stepfather to have that child because it could put her life at risk," he said.
"I believe that in this sense, medicine is more correct than the church."
But the cardinal said "life must always be protected, the attack on the Brazilian church is unjustified".
'Worse than rape'
The nine-year-old from the northeastern state of Pernambuco in the world's largest Roman Catholic nation, was found to be four months pregnant last week after allegedly being raped by her stepfather.
"It is a sad case but the real problem is that the twins conceived were two innocent persons, who had the right to live and could not be eliminated"
Cardinal Giovanni Battista Re, senior Vatican cleric
Abortion is a crime under Brazilian laws except in cases of rape, if the woman's life is in danger or if the foetus has no chance of survival.
Doctors said they decided to terminate the pregnancy because the girl's life was in danger due to her young age, and because she was carrying twins.
But Sobrinho, the archbishop of Olinda and Recife, in declaring the excommunication, said the abortion went against "the law of God".
The stepfather was not excommunicated because the church said that his action, although deplorable, was not as bad as ending the life of an unborn child.
"It is clear that he committed a very serious sin, but worse than this is the abortion," Sobrinho said.
Under church law, excommunication is automatic for followers who have, perform or help procure an abortion.