A 50-year-old youth worker allegedly raped a transgender teenager he met through a children's home, the High Court has been told.
Prosecutors claimed he sexually abused a vulnerable victim after they formed what was described as a "buddy relationship".
The County Londonderry man, who also faces historical charges of molesting his own son, cannot be named for legal reasons.
He denies all allegations involving his child, but has made limited admissions about sexual activity with the 14-year-old currently in foster care.
Temporary bail was granted for what defence counsel accepted would be a "last Christmas" before his client begins a period in custody.
The man is charged with rape, sexual activity with a child by a person of trust, and meeting a child following sexual grooming on dates in August this year.
A Crown lawyer said that case involved transgender child aged 14 who now identifies as male.
It was claimed the accused got to know the teenager, referred to as XY, through his work at a children's residential facilities.
Following an arranged meeting at a high street store they went back to the man's home, the court heard.
Prosecution counsel said the child described kissing and cuddling on a sofa before the alleged rape in the defendant's bedroom.
"The child is particularly vulnerable given their status as transitioning, and there are significant concerns this applicant has abused those vulnerabilities," she contended.
Lord Justice McCloskey was told the man attempted suicide after being made aware of the allegations against him.
Referring to statements from work colleagues and witnesses, the barrister went on: "They noted he treated the child different from others in the facility, in what appeared to be a buddy relationship."
Examinations of the accused's phone were said to have revealed internet searches for legislation on sexual activity with a child.
It was also claimed that he told XY in a Facebook messenger chat: "It wasn't your fault, I'm the adult and I'm still your friend."
He is also separately charged with buggery, indecent assault on a male and gross indecency with a child.
Those alleged offences were committed against his son on dates between January 2000 and December 2003.
The accused sought temporary bail to stay with relatives over the Christmas period.
Opposing the application, the prosecutor expressed concern he is "neither willing nor able to control his urges".
She submitted: "He is alleged to have committed particularly traumatising and heinous offences against a child in his care, a child he knew to be particularly vulnerable."
Stephen Mooney, defending, confirmed his client denies the rape charge.
But based on some admissions about activity with XY, the court was told the accused now faces potential imprisonment.
"He is seeking release for a finite period of time to spend what presumably will be his last Christmas with his family for a significant period of time," Mr Mooney said.
Granting bail for a three day period, the judge acknowledged: "This is a very difficult and troubling case, for obvious reasons."
He imposed a series of strict conditions as part of the temporary release, including bans on using the internet or unsupervised contact with anyone under 16.