The man who torched a Queens home — killing himself and two others — was busted days earlier for staging a home-invasion sex attack that he hoped would get his ex-boyfriend arrested, police and law enforcement sources told The Post.

David Abreu Nuñez called police around 7:15 p.m. last Saturday claiming he was attacked at his home on Morris Avenue in The Bronx.

The 23-year-old told cops he was inside the Fordham Heights apartment when he heard a knock. When he opened the door, he said, he saw two older women — but was then forced inside by four men wearing masks and demanding money, law enforcement sources said.

He claimed the attackers said his ex-boyfriend’s name before shoving him and causing him to lose consciousness, the sources said.

Nuñez stated he was then zip-tied and sexually assaulted — but when police and medics showed up, he had no visible signs of injuries, the sources added.

He was captured on building surveillance video being taken out of the apartment on a gurney before he was brought to St. Barnabas Medical Center for further evaluation.

He later admitted to police he staged the crime, and had made the bogus claims in hopes his ex-boyfriend would be arrested, law enforcement sources said. Instead, Nuñez was charged with filing a false report, police said.

The next day, Nuñez’s roommate booted him from the apartment because of the stunt.

“I told him he couldn’t be in my house,” said the roommate, who spoke on the condition of anonymity.

On Wednesday, while Nuñez was staying in East Elmhurst with Raul Moreno and relatives who were visiting from the Dominican Republic, the man became irate after the family asked him to leave, different police sources said.

Nuñez doused the kitchen with gasoline and set it on fire, killing 6-year-old Emma Dominguez and her 76-year-old grandfather, Claudio Rodriguez.

Two others, including Emma’s 10-month-old brother Liam and her 35-year-old mother Elizabeth Rodriguez, were critically injured, and suffered burns on more than 70 percent of their bodies, relatives and authorities said.

“It could have been me,” the ex-roommate said. “I kicked him out.”

She added: “He could have burned me but he didn’t? So why did he do it to those people?”

The roommate called Nuñez “a good person,” even though she claims she called a woman in the Moreno family to warn her about him when he shacked up at the Queens home.

“I told her that he was dangerous … that he tried to harm himself,” the roommate said.

The roommate claimed Nuñez and his ex-boyfriend had a bad breakup.