Mawawe Ibraham Karam, 28, was due to stand trial for the rape at Nottingham Crown Court (pictured) next week.
After exposing himself, he was removed from the courtroom, but could be heard shouting: “I’m guilty, I’m guilty”.
He was later brought back before the judge and changed his plea to guilty. Karam, of Herbert Road, Nottingham, will be sentenced on Thursday.
Little detail of the rape was given in court but Nottinghamshire Police said it happened on 25 March in the city centre.
Judge Michael Stokes QC said a 17-year-old was “dragged up an alleyway, stripped naked and raped”.
An issue was discussed in court about whether Karam would have been capable of attacking the woman because of a possible medical condition.
The court heard Karam came to the UK illegally, but had since been given indefinite leave to remain.
After pleading guilty Karam asked Judge Stokes to sentence him that day, repeatedly shouting: “Please judge, please sentence me today, please.”
The case was adjourned so that the victim’s family could be present for sentencing.