An 18-year-old man has been registered a sex offender and been sentenced to two years with the final 18 months suspended for having sex with a 15-year-old girl.

The teenager, who was 17 at the time of the sexual encounter, admitted the offence and said he hadn't got a clue that it was against the law to have sex with someone her age.

The youth, who cannot be named for legal reasons, pleaded guilty at Dublin Circuit Criminal Court to having sex with an underage person on 2 September, 2011.

The court heard that the accused has three previous convictions and is currently serving a sentence for assault and is due to be released next July.

Judge Carmel Stewart sentenced the 18-year-old to two years in jail with 18 months suspended, to run concurrently with the sentence he is now serving.

The judge said both the accused and the victim had had difficult lives.

She accepted that the accused was attempting to turn his life around and was anxious to play a role in the life of his first child who is due to be born early next year.