The verdict was announced in Kot Lakhpat jail amid tight security.
Imran has also been sentenced to seven years in jail with a fine of Rs 1 million for desecrating the body of a minor.
Ali faces further charges in the cases of at least seven other children attacked in the Punjab city of Kasur, several of whom were killed.
The Prosecutor General of Punjab, Eihtesham Qadir Shah, announced the court's verdict at a televised news conference. "The convict was then told that anything he says will be used against him in court, after which he confessed".
However, they said Imran should be hanged in a public place so that others learn a lesson from his fate.
However, her mother, Nusrat Amin, told Al Jazeera she thought the death sentence was still not enough after what prosecutors say he did to their daughter.
According to a police official, the autopsy of the girl who was found dead in a rubbish dump on January 9 in Kasur revealed she had been raped and strangled to death by the suspect.
Her case was the 12th such incident to occur within a 10 km radius in the city over a 12-month period.
The heinous nature of the crime had seen immediate riots break out in Kasur - in which two people were killed - while #JusticeforZainab became a rallying cry for an end to violence against children.
Ali was a neighbor of Zainab, and closed-circuit video footage from the day Ansari was abducted shows her walking off calmly with a man. His lawyer had withdrawn from the case after Imran confessed. The Lahore High Court had given seven days for completion of the trial.
A special prosecution team headed by Abdul Rauf Wattoo prosecuted the suspect during the trial. Zainab's father was also present for the verdict. Zainab was kidnapped from near her aunt's house in Kasur on January 4. Her body was found in garbage near her home three days after her disappearance.
The arrest brought to light eight more such killings and many Pakistanis have demanded he be publicly executed. Protesters accused the government of inaction and a media campaign subsequently led to Ali's arrest.
A serial killer has been sentenced to death for the murder of eight children in Pakistan.