An American woman and her late boyfriend have been exonerated of the 1987 rape and murder of her four-year-old niece after spending nearly 30 years behind bars.

Joyce Watkins, 74, was convicted of the rape and murder of her great-niece Brandi in 1988.

Police and prosecutors said she and her boyfriend, Charles Dunn, brutalized the girl so badly that she died while she was in their care.

Watkins, then aged 38, took Brandi to a hospital in Nashville nine hours after collecting her from another woman’s home, where the child had spent two months and where neighbors suspected she was being abused.

A doctor ruled that Brandi, who was unconscious,  had been raped, and that she died as the result of injuries inflicted in the nine hours Watkins and her boyfriend had her in their care.

Dunn, who was known as Charlie, died in prison in 2015, and Watkins was released that same year after serving 27 years.

On Wednesday, a judge overturned their convictions, Dunn’s posthumously after an appeal from The Innocence Project which questioned the doctor’s analysis of when Brandi had been raped and injured.

It found there was no proof of when the girl had been brutalized, and that the doctor made the assertion by looking at marks on Brandi’s skin rather than any internal injuries.

A report by the Nashville Criminal Review Unit also suggests that the girl’s then 19-year-old male cousin, who was enlisted in the Marines at the time, may have been the one who raped and beat her.

No one else has been arrested for the crime and it’s unclear if he is still alive.

After the hearing, Watkins said: ‘It’s been a long struggle, but I want to thank the DA’s office.

‘I want to thank Mr. Gichner here with the Tennessee Innocence Project and all the people for their prayers and just helping me to get out of this mess which cost me half of my life for nothing.’

Charlie Dunn’s daughter Jackie said: ‘It’s a bittersweet day. I wish my daddy was here to witness this day. He knew he was innocent. He knew he did not commit those crimes.

‘He lost his mother, his two brothers, his sister and his son. So many people lost and he was innocent. He died in a place he was never supposed to be.’

The report also detailed how Brandi had suffered bruises while in the care of Rose Williams, the Marine’s mother, and that she was reported to social services.

Brandi’s mother, Louis Lockhart, has long supported Watkins. She said on Wednesday that she never believed she was responsible for killing her daughter.