James Allen, 27, has been charged with raping a woman in her South Loop apartment early Sunday, among other crimes. View Full Caption DNAinfo file art; Cook County Sheriff

COOK COUNTY CRIMINAL COURTHOUSE — A naked man raped a stranger before burglarizing multiple condominiums in a South Loop building early Sunday, prosecutors said.

James Allen, 27, entered the building in the first block of East 16th Street about 5:30 a.m. Sunday and began checking for unlocked doors, Assistant State's Attorney Kathryn Roy said during a bond hearing Monday.

Allen was naked at the time, prosecutors said. It is unclear how he gained access to the building.

Allen walked into a unit on the fifth floor, prosecutors said, and found a 31-year-old woman asleep in her bedroom. Her friend, a 25-year-old man, slept on a couch in the living room.

Allen grabbed the woman's neck and hair before raping her, according to Roy. The victim's friend, who was awakened by the sound of the woman "whimpering in pain," rushed into the bedroom and pushed Allen off his friend, authorities said.

That's when Allen began to chase the friend, who ran into the hallway and down a staircase to the lobby to call for help, according to prosecutors.

Allen briefly pursued the friend, Roy said, but ultimately left the staircase on the fourth floor, where he entered an apartment and stole a cellphone, glasses and other items.

When one of three sleeping roommates in that apartment woke up and confronted Allen, prosecutors said, he left the unit and headed to the ninth floor.

Allen tried to steal a laptop, wallet and guitar from a ninth-floor condo, Roy said — but was thwarted by a 44-year-old resident who confronted him and called police. At that point, court records show, officers were already in the building.

Allen was arrested about 6:10 a.m. Sunday on the ninth floor, according to an arrest report. He was still naked at the time.

Allen, of the 2600 block of West 83rd Street, is charged with aggravated criminal sexual assault, home invasion and residential burglary. According to prosecutors, he admitted to "having sex with a woman" Sunday and entering multiple units in the condominium building.

The rape victim was taken to Mercy Hospital, where a rape kit was collected.

At the time of Sunday's attack, Allen was on probation for a 2016 burglary conviction. He also has convictions for domestic battery and criminal damage to property.

Allen remained hospitalized Monday for a psychological evaluation and did not appear during his bond hearing at the Leighton Criminal Courthouse, 2650 S. California Ave.

Cook County Judge Michael Clancy denied Allen bail.

A public defender declined to speak on Allen's behalf Monday since he was unable to speak to Allen before his brief hearing.