The reputed MS-13 gangbanger charged with raping an 11-year-old Brooklyn girl in her bed carried out his sick attack as the victim’s brother was in the bunk below her, prosecutors revealed Sunday.

Julio Cesar Ayala, 18, pushed aside an air conditioner and slid through the second-floor window of his young victim’s Prospect Lefferts Gardens home late Wednesday, prosecutors charged during his arraignment in Brooklyn Criminal Court.

The creep — who was carrying a phony US immigration green card — first flicked the lights in the room on and off and shuffled things around on top of a dresser before climbing into the top bunk of the bed with the girl, according to officials.

As the victim’s brother lay in the bunk below, Ayala undressed the girl and began to rape her, authorities said.

The preteen let out a terrified scream, sending her parents running into the room and Ayala fleeing the apartment — leaving his Chicago Bulls cap lying on the dresser, authorities said.

Outside the building, Ayala changed his shirt in an apparent bid to throw off the heat, but the swap was caught on surveillance camera footage, officials said.

Cops also found footage from before the attack showing Ayala wearing the Bulls cap, prosecutors said.

Investigators were eventually able to track Ayala going into his apartment building on East 21st Street — less than half a mile from the victim’s building.

When police pounded on Ayala’s door Saturday afternoon, a woman answered, as Ayala peered over her shoulder.

He vaulted out the apartment window and sought refuge in an under-construction building nearby but was quickly found and cuffed by cops.

“Yes,” Ayala told cops in an apparent admission to the vile allegations, according to prosecutors. “I have never done anything like this before.”

Ayala — who has no criminal record in the city but has been identified as a suspected member of the vicious MS-13 gang by police sources — was carrying phony Social Security and immigration cards as his only identification when he was nabbed, prosecutors said.

The El Salvadoran’s actual immigration status was not clear.

Ayala moved to Brooklyn just months ago from Virginia and works full-time at his uncle’s air- conditioning business, his Legal Aid lawyer said in arguing for low bail.

The young victim was unable to pick Ayala out of a police lineup, the lawyer, Anna Boksenbaum, said in arguing that the arrest was a case of mistaken identity.

Ayala, who’s facing a slew of charges including rape, burglary, and possession of a forged instrument, was ultimately held on $500,000 bail.

“We’re shocked,” said Karen Ayala, 17, who was in attendance at her cousin’s arraignment. “We don’t think he’s capable of doing something like this.”

In Prospect Lefferts Gardens, neighbors were hungry for justice — through the courts or otherwise.

“This freak, he needs the neighborhood to take care of him,” said resident Tanyka Williams.

“That’d be justice.”

Additional reporting by Larry Celona