Manfred Edgar, 65, made the admission moments after he cut his wrists in the detention area of Edinburgh’s St Leonard’s Police station.
The High Court in Edinburgh heard yesterday that Edgar had tried to take his life on 28 July this year.
The court heard how officers had detained him earlier that day in connection with alleged historical sex offences against two girls.
Details of his suicide bid were given following a hearing in which Edgar, described as a prisoner of HMP Saughton, pleaded guilty to two charges of abusing the girls between January 1991 and June 2008.
Prosecution lawyer Bill McVicar told Judge Lord Boyd about Edgar’s conduct after officers arrested him at his Edinburgh home.
Edgar, a retired courier, sat in the dock weeping as Mr McVicar addressed the court.
Detectives were wanting to interview Edgar in connection with the alleged abuse, which took place at various locations in Edinburgh
The advocate depute said: “While he was in police custody, the accused attempted to commit suicide within a cell at St Leonard’s Police Station by cutting his wrists.
“He said to the officer who entered his cell ‘my life is over, I want to die.’
“He further said as first aid was given ‘it’s all true what they say about me. I don’t want to live anymore,’ and that he ‘had abused the trust in the worst possible way’ and ‘it’s all over’.
“The accused was thereafter held in police custody to appear in court.”
Mr McVicar told the court that Edgar targeted his first victim, who cannot be named for legal reasons, when she was just four in 1991.
He repeatedly abused her until she turned 11.
Edgar’s second victim – who also cannot be identified – was first targeted in June 2003 when she was aged just four. She was repeatedly sexually assaulted until she was nine-years-old.
The court heard how Edgar was arrested after his victims plucked up enough courage to speak to the police earlier this year.
He was taken into custody and charged.
Edgar pleaded guilty to the offences at the earliest possible opportunity, the court heard.
Lord Boyd deferred sentence for reports and placed Edgar on the Sex Offenders Register.
He will be sentenced at the High Court in Edinburgh on 15 December.