A Queens man accused of setting a fire that killed four people at a house in Flushing last month did so to “get out his rage” after getting fired from his job, prosecutors said in court Thursday.

Roman Amatitla, 38, did not know anyone in the building, Assistant District Attorney Gabriel Reale said at Amatitla’s arraignment on multiple murder and arson charges.

After igniting a piece of paper in the first-floor vestibule, Amatitla walked to the nearest street corner, sipped a beer and watched as terrified residents screamed for their loved ones and jumped from the windows, Reale said.

“He admitted to intentionally starting the fire to get out his rage,” the prosecutor added.

Amatitla was arrested earlier this week for the March 16 fire, which killed 3-year-old Sihan Yang, 50-year-old Chengri Cui, and two other victims — a 61-year-old woman and a 63-year-old man whose identities authorities have yet to release.

City medical examiners have ruled all their deaths homicides. Amatitla also faces assault and petit larceny charges in the case.

In court on Thursday, prosecutors detailed how Amatitla’s firing from a food processing job allegedly led him to plot destruction against strangers.

Once he selected the red-brick home on the corner of College Point Boulevard and Avery Avenue, they said, he walked in and out several times, then went to a nearby gas station.

“He acquired two beers, paid for one, stole the other and asked for lighters from the clerk,” Reale said, summarizing statements he said Amatitla made after getting arrested. When the clerk told him the lighter wouldn’t be free, according to Reale, the defendant asked for a book of matches instead.

Prosecutors said Amatitla followed a resident into the building around 12:30 p.m. on the day of the blaze. Once inside, he allegedly set the fire and allowed it to grow as it consumed trash nearby.

“He indicated that he watched as people jumped from various windows, some of them living, one of them dying,” Reale said, adding that Amatitla was present as the 3-year-old’s mother came back to the home and screamed.

More than 200 personnel responded as the flames spread through at least five apartments on the second and third floors, according to FDNY officials. Two firefighters were injured when the staircase collapsed between those floors, sending them plunging to the basement, Reale said.

Three of the victims were declared dead at the scene, while the fourth died at the hospital, officials said at the time. Several others were injured.

Prosecutors said Amatitla had no criminal record before his arrest. U.S. marshals and NYPD detectives took him into custody Tuesday, according to authorities.

Amatitla did not speak in court on Thursday, but listened to the proceedings through a Spanish translator. Judge Thomas Wright-Fernandez granted prosecutors’ request to hold Amatitla in jail as the case proceeds.

Following the arraignment, Queens DA Melinda Katz called the incident “pandemonium” and “one of the greatest crimes that this borough has seen in a very long time.”

Amatitla’s attorney, Vivian Cedeno, told reporters outside the courtroom that her client is presumed innocent until proven guilty. He faces 25 years to life in prison if convicted on the murder charges.

Tenants of the building, which court filings say had been divided into as many as 14 units, told Gothamist the property regularly had trash-strewn hallways, leaks and debris-blocked stairways. City records show a lengthy history of housing violations, fines and lawsuits tied to the building.