The girl was taken by the terrorists from the village of Kosho, south of the Yazidi hub of Sinjar in northern Iraq, together with her mother and sisters.
She was freed during an operation by the security forces on Thursday in the west Mosul neighbourhood of Tanek, federal police chief Lieutenant General Raed Shakir Jawdat said in a statement.
The elite Counter-Terrorism Service has been operating in the area and secured more than half of the neighbourhood on Thursday.
"They who kidnap these children are monsters," Major General Jaafar al-Baatat, Jawdat's top aide, said in a statement which was released with a video showing the girl at a police base south of Mosul.
Vian Dakhil, a prominent Yazidi lawmaker who helped bring her minority's plight to the world's attention when ISIS teerrorists swept through the region in 2014, said the girl's release had been carefully planned.
"When Daesh (ISIS) took her village on August 15, 2014, she was eight years old and she was kidnapped with her mother and her sisters," she told AFP. "She was initially taken to Tal Afar and was sold on to Mosul."
Yazidis are neither Arab nor Muslim and when ISIS swept across northern Iraq almost three years ago, it carried out massacres against the minority which the United Nations said qualified as genocide.
Most of the several hundred thousand members of the minority live in northern Iraq, mainly around Sinjar, a large town which anti-IS forces have now retaken but was extensively destroyed.
Sisters held in Syria
ISIS terrorists captured Yazidi women and turned them into sex slaves to be sold and exchanged across their self-proclaimed "caliphate". Around 3,000 of them are believed to remain in captivity.
On the police video, the girl stands silently, wearing a light green head scarf as officers try to reassure her.
"She has two sisters who were sold and sent to Raqa," said Dakhil, referring to the Syrian city that is still controlled by ISIS and the other main hub of the "caliphate". "They are still there."
Dakhil explained that the girl's two other sisters and mother were bought back from ISIS, a method which has been used by the authorities and Yazidi organisations to free hundreds of women, and now live in Germany.
The girl and her family are originally from Kosho, the same village Yazidi rights activist and Nobel Peace Prize nominee Nadia Murad is from.
Vian Dakhil said the girl's father had a disability.
"Her cousin who lives in a camp for the displaced near Dohuk (in autonomous Kurdistan) is coming to fetch her," she said.
The Yazidi community, which follows a unique faith, celebrated their New Year on Thursday.
Many of towns and villages have now been retaken from the terrorists by the Iraqi security forces but they are often still unsafe or need to be completely rebuilt.