A father of two teenage girls has lost a lengthy legal battle to get custody of his children after his ex-wife married a registered sex offender.

The divorcee took legal action saying he feared his girls may fall prey to the convicted criminal, who served four years in prison in 2003.

He was jailed for the attempted sexual abuse of his then 15-year-old stepdaughter from a previous marriage.

The case has been dragged through the court system in Nebraska, US, until the state Supreme Court upheld the lower courts’ rulings, finally ending the father’s legal challenge.

Previously, a Phelps County District judge ruled there was no significant risk to the pair.

Refusing to accept the decision, the father, who has not been named, took his fight to the Nebraska Court of Appeals, which sided with the earlier judge, concluding the teenagers were not in danger.

But he fought on for custody of his children, taking his battle to the Supreme Court judges.

There, a divided court upheld the ruling with a four-justice majority, with two justices finding in favour of the father.

One of the two, Justice William Connolly, wrote a letter criticising his peers' decision.

Timeline: Steven Avery's convictions Show all 5 1 /5 Timeline: Steven Avery's convictions Timeline: Steven Avery's convictions 1985: Steven Avery is falsely convicted of raping a Penny Beernsten She was jogging along the shore of Lake Michigan when she was threatened with a knife and attacked. Ms Beernsten identified Avery as her rapist from a line-up that did not include the actual attacker. AFP/Getty Images Timeline: Steven Avery's convictions 2003: Conviction overturned Avery's 32-year prison sentence was overturned after DNA testing by the Wisconsin Innocence Project proved his innocence and found a hair from Gregory Allen. He was convicted of the rape and Avery was released. Timeline: Steven Avery's convictions 2004: Avery files federal lawsuit against Manitowoc County police A Wisconsin Department of Justice investigation found police had committed no criminal offences or ethics violations, sparking a lawsuit from Avery seeking $36 million compensation. Timeline: Steven Avery's convictions 2005: Avery is arrested for Teresa Halbach's murder His Avery Auto Salvage business was the freelance photographer's last appointment of 31 October. She was reported missing four days later and police later found her car, bones, teeth and belongings at the site. Avery pleaded not guilty but was sentenced to life in prison in 2007. Timeline: Steven Avery's convictions 201: Netflix releases Making a Murderer The 10-episode documentary came after Avery's conviction was upheld in a 2011 appeal.

Retiring earlier this month, he wrote: “It leaves the noncustodial father, who is willing and able to care for his children, feeling helpless to protect his children.”

As reported in the Journal Star, he said the stepfather should undergo an independent evaluation to assess if the girls were at risk.

And Justice Lindsey Miller-Lerman also came down in favour of giving the father custody.

She found that the current circumstances were worrying similar to the original situation that led to the stepfather's conviction.

Nebraska law states there is a presumption that since the stepfather is a sex offender and has access to the girls, they are at risk.

But this can be overridden by the custodial parent, their mother, presenting evidence to the contrary.

The justices wrote: “If she presented such evidence, then the presumption disappeared and the district court, as trier of fact, was not required to find that [the stepfather] was a significant risk.”