Manuel Valero, from Spain, and his American husband Gordon Lake were blocked from leaving Thailand with their daughter Carmen after the surrogate declined to sign necessary paperwork following the birth in January 2015.
They accused the mother, Patidta Kusonsrang, of reneging on the surrogacy once she discovered the couple were gay.
Rachapol Sirikulchit, the couple's lawyer, told reporters the court had granted “sole custody to Gordon Allan Lake” after the court ruling in Bangkok.
Reporters were not allowed inside to hear the ruling. The court is expected to release a written statement later on Tuesday.
“We are really happy that this nightmare is going to end soon,” a tearful Valero told reporters outside court.
“After 15 months Carmen will fly to Spain. We don't know when but it will be soon,” he added.
The two men, who live in Spain but are currently caring for the child in Bangkok, have spent more than a year fighting a custody battle.
It was complicated by recent changes to Thailand's surrogacy laws and the fact that the kingdom does not legally recognise same-sex marriage.
Their other child, a son, has spent the past year living with Valero's sister in Spain.
The surrogate mother Patidta denied in local press interviews when the row surfaced that she refused permission because the couple were gay.
She has since shied away from the media and has yet to explain what motivated her decision.
Thailand for years hosted a thriving yet largely unregulated international surrogacy industry popular with same-sex couples. But a string of scandals in 2014 spurred the military government to ban foreigners from using Thai surrogates.
One high-profile case saw an Australian couple accused of abandoning a baby with Down's syndrome carried by a Thai surrogate while taking the baby's healthy twin sister.
In another case a Japanese man was controversially found to have fostered at least 15 babies with surrogates.
The ban came into force after Carmen was born.