An illegal Chinese immigrant, bitter over his failure to achieve the American dream, repaid his cousin’s kindness by butchering the man’s wife and four young children, cops said Sunday.

Mingdong Chen, 25, showed no remorse when he confessed to slaughtering the family that allowed him to live in their Brooklyn apartment and admitted that he committed the atrocity because he envied their way of life, a police source told The Post.

“The family had too much,” the source quoted Chen as saying.

“He meant that the family had better income and a better lifestyle than him . . . He was jealous and just killed them.”

Chen was charged Monday but did not enter a plea.

NYPD Chief of Department Philip Banks III said Chen had cited his inability to make it in America as his motive for the slayings, which apparently took place while the victim’s husband Yi Lin Zhuo was at work.

“Everyone here is doing better than me,” Banks quoted the suspect as saying during a confession in Mandarin Chinese, the only language Chen speaks.

A family friend said slain mom Qiao Zhen Li had tried to boot Chen out of her family’s Sunset Park home.

“She told him, ‘You just leave my house,’ ” said Xiao Wei Yang, 31.

“She was never thinking he’d use the knife to cut and kill everyone . . . She was just helping him, and he just killed her whole family.”

Yang learned of the attempted eviction from a cousin of Li’s who had visited the apartment shortly before Chen’s alleged Saturday-night rampage.

“My friend went to visit her cousin a couple hours before it happened,” Yang said. “She left, so she just said thanks to God.”

About three minutes before cops and ambulances arrived, a neighbor, who asked not to be identified, heard a woman in the house screaming “Help! Help! Help! Help!’’ in the Chinese dialect of Fukinese.

Sources said Chen, who came here illegally from China and worked as a cook, used a butcher knife to slash and stab Li in the face — lopping off several of her fingers when she tried desperately to protect herself.

Cops found Li, 37, in the kitchen with her son Kevin Zhuo, 5. Both were alive but died a short time later at hospitals. The other children — William Zhuo, 1, Amy Zhuo, 7, and Linda Zhuo, 9 — were found slain in a rear bedroom.

Two of the kids, including the baby, had been decapitated, and there was a trail of blood throughout the house, sources said.

“It’s just a scene you’ll never forget, I’ll just leave it at that,” Banks said.

Li’s husband — who arrived home after his family was massacred — appeared dazed when he stepped out of the 66th Precinct station house to talk on his cellphone Sunday.

He walked slowly and ignored questions from reporters before cops escorted him back inside, then took him away out a rear entrance.

A man who accompanied him to the station house, Peolouen Chang, said the husband had emigrated from the coastal Fujian province in China before any of his children were born.

Banks said the nightmare scene was discovered by Zhuo’s sister and brother-in-law, who went to the 57th Street apartment after Li tried to call her husband to tell him Chen was “acting suspicious.”

When she couldn’t reach her husband, Li called her mother-in-law in China, who also couldn’t reach him and contacted Zhuo’s sister who lives nearby, Banks said.

The sister and her husband banged on the door until Chen finally opened it and they saw him “covered in blood.”

They then called 911, and two detectives who happened to be investigating a robbery pattern nearby raced to the scene.

The detectives, William Greer and Giovanni Talavera, nabbed Chen as he tried to escape out the front door at about 10:45 p.m., still carrying the bloody knife, a source said.

“If those detectives hadn’t been in the area, he could have gotten away with it,” the source said.

“It’s very hard to track a suspect with no criminal history. And this suspect was a drifter, a nomad. It would have been very hard.”

A neighbor Amy Chang, 15, said she ran outside when she heard sirens, and saw EMTs struggling in vain to save one of the children .

“He was wearing yellow pajamas,” she recalled. “He was bloody. They were trying to help him. But he wasn’t moving. He had bandages on his legs. “To kill a kid, it’s the worst.”

Chen also allegedly attacked two cops while he was being questioned in the 66th Precinct station house.

A source said that while one of his hands was cuffed to a table, Chen kicked the table into a sergeant serving as an interpreter, knocking him to the floor.

Chen then used his free hand to punch a detective, the source said.

He was charged with one count of first-degree murder, four counts of second-degree murder, two counts of second-degree assault, five counts of fourth-degree criminal possession of a weapon and resisting arrest.

Chen looked calm and said nothing as he was walked out of the station house Sunday evening.

A distraught cousin of the dead mom recalled having met Chen when he lived with the victims’ family in the past and said Chen had worked as a cook but couldn’t hold down a job.

“He’s lazy. He doesn’t work too hard,” Gao Yun, 29, said after stumbling upon the crime scene Sunday and breaking down in sobs when cops told her what had happened.

Yun said Chen most recently was working at a restaurant in another state but had been fired about two weeks ago.

“The guy is crazy,” Yun added, twirling her index finger next to her right temple.

Banks said Chen has been “bouncing around” since entering the United States in 2004, first living for a time in Chinatown in Manhattan before moving to Chicago.

At some point, he returned to New York and was living with Li’s family for eight to 10 days before the carnage, Banks said.

Chen has no known history of mental illness and no arrest record in New York City, Banks said, adding that cops were checking to see whether he has ever been busted elsewhere in the country.

Additional reporting by Kathryn Cusma, Adam Janos, Antonio Antenucci and Daniel Prendergast