Warning: Graphic language

Police shot and killed a disturbed man after he walked into one of Brooklyn’s most prominent synagogues early Tuesday and stabbed someone there, sources said.

The bloodshed at the world headquarters of Chabad-Lubavitch at 770 Eastern Parkway in Crown Heights happened shortly after 1 a.m., sources said.

A Chabad spokesman said witnesses reported that the man said “Kill the Jews,” but police said the man might have shouted, “I will kill all of you.” One witness told The Post that the man did not talk about killing Jews.

Calvin Peters, 49, walked into the basement of the synagogue, where people were praying, law enforcement sources said.

Witnesses took cellphone photos and video of the incident and its aftermath.

“According to witnesses, he was heard saying repeatedly, ‘Kill the Jews!’” Chabad Rabbi Motti Seligson said.

“Several other individuals immediately intervened. While we are very pained by everything that has unfolded, we are very grateful to the police for their quick response and are working closely with the authorities in their ongoing investigation.”

Seligson said the victim was Levi Rosenblat, a young rabbinical student from Israel. The 22-year-old was in stable condition at Bellevue, law enforcement sources said.

Peters had 19 prior arrests dating to 1982 for a wide variety of crimes in New York City, Nassau County and Delaware, according to law enforcement records.

The offenses included jumping a turnstile, larceny, possession of a controlled substance, using a credit card that wasn’t his, contempt of court and burglary.

Peters had a listed address in Valley Stream, LI, and a man who answered the phone there said the attacker’s family was in mourning.

“Have you seen the video? The video speaks volumes,” he told The Post. “It’s a tragedy. We’re just grieving.”

Asked whether cops were justified in shooting Peters, the man said: “We don’t want to get into the middle of a battle with police.”

Later on Tuesday afternoon at that Valley Stream home, a man who identified himself only as Peters’ brother-in-law briefly spoke to reporters.

“A father, a brother and a good man died,” he said. “It’s a tragedy. We aren’t making any statements today. Please give us our privacy and allow us to grieve.”

John Miller, deputy commissioner of intelligence and counterterrorism, said police believe this attack was an “isolated incident.”

“It appears to involve an individual who is known to the New York City Police Department,” Miller said. “(Peters) has a history of being an emotionally disturbed person and acting out in other places.”

Peters was last seen by loved ones at 11 a.m. Monday, leaving his Long Island home for a dental appointment that he never made, law enforcement sources said.

Peters, a former Brooklyn resident, was spotted in that borough Monday afternoon by a friend, sources said.

Then at about 5:15 p.m. Monday, Peters first visited the synagogue and appeared to be “highly suspicious,” according to security guard Shimon Liberow.

“I chased him out, he was highly suspicious. He looked around and gave me a very stern look,” Liberow said. “He caught my attention.”

At one point, Peters said he wanted to convert to Judaism, but the guard and nearby worshipers didn’t buy it.

“I confronted him at the door. I stopped him from going in. I knew he was up to no good. He was surveying around,” Liberow said. “I said, ‘Can I help you?’ He said, ‘You have a problem?’ I said, ‘Yes.’

“He asked if he can become Jewish, if he can convert,” Liberow added. “My friend told him you have to be Jewish to pray here. He abruptly left.”

Peters then got into a silver Nissan Rogue and drove a short distance away. Police found the SUV hours after the attack and towed it away.

He returned at 12:45 a.m. Tuesday and asked if they had any books in English.

He was told no and then “escorted out,” law enforcement sources said.

Peters’ final return came at 1:36 a.m., when he entered the building, walked up to Rosenblat and said, “I’m going to kill you,” sources said.

He stabbed Rosenblat in the left temple and inflicted lesser wounds to the left side of his face, sources said.

Witness Israel Gottdenger, 26, told The Post that Peters nonchalantly strolled into the synagogue without giving any hint about the mayhem that was to follow.

“I entered the building with him (Peters), I even held the door open for him,” said Gottdenger. “It’s a very public building and people of all kinds are always walking in, white, black, everyone.

“He was just going crazy,” Gottdenger added. “He said, `I want to sit down, I want to get a Bible, who wants to die tonight,’ he kept changing his words. He was either really high on drugs or an (emotionally disturbed person).”

Rosenblat was so immersed in reading religious text, he never saw the attack coming.

“He’s a very serious student. He’d been studying all day,” witness Levi Deutsch said of the victim. “He was stabbed in the side of the head. He was conscious but he was bleeding a lot.”

Another witness flagged down cops who were passing the headquarters.

Officers then confronted the man in an encounter that was captured on a dramatic video.

As Peters brandishes the knife, the first officer to respond — Timothy Donohue — pulls his weapon, prompting onlookers at the synagogue to say, “Hey officer, don’t do it” and implore Peters to drop the knife.

Peters then shouts, “You gonna shoot me?,” prompting the onlookers to exclaim, “No, no, no, don’t shoot, don’t shoot.”

Peters then repeats, “You gonna shoot me?,” to which the officer responds, “If you don’t drop the knife I will.”

After several demands from the officer, Peters then puts the 9-inch knife down on a table and puts his hands up, prompting Donohue to holster his gun.

It appeared as if the encounter had been defused. But Peters suddenly grabs the knife again, prompting the officer to shout, “Stay the f–k away from the knife now.”

“At that point, the male subject picked up the knife and advanced the officer,” NYPD Chief of Department James O’Neill said.

Other officers then appear in the video as Peters storms around, brandishing the knife.

Then, moments later, a single shot is heard, after the camera turns away from the chaotic incident.

Peter was within 10 feet of officers when he lunged at them and Officer Roberto Pagan shot the maniac, law enforcement sources said.

“Backup officers continued to order the male to drop the knife,” O’Neill said. “After repeated commands, one officer fired a single shot, striking the male in the torso.”

Another video shows officers standing over the man as he was handcuffed.

“It’s the first time this has happened at a New York synagogue,” one member said. “I come here every day. To know that somebody died here, it’s scary. It needs to be a secure place.”

Tuesday’s attack might have exposed a shortcoming in the city’s mental health system, Mayor Bill de Blasio said.

“This incident also highlights the urgent need for increased services for emotionally disturbed or troubled people,” the mayor said.

“Preliminary reports suggest the assailant in this case suffered from mental health issues. We as a society must do more for those who struggle with these challenges, and it is why the city has launched a new plan to improve access to mental health care and treatment for those in need.”

NYPD Commissioner Bill Bratton said responding officers appeared to do everything they could to avoid using deadly force.

“Preliminarily the shooting looks like it was justified based on my initial impression of what I’ve seen of the video,” Bratton said.

“You have an individual with a knife, who had allegedly just stabbed an individual. You had three responding officers who were clearly attempting (to avoid gunfire and), repeated, `Put the knife down, put the knife down.’”

Bratton added: “The shooting, while unfortunate, might have been unavoidable.”

De Blasio, who last week questioned whether NYPD cops target young black men, praised officers at this scene.

“They responded quickly to a tense and dangerous situation, and while any loss of life is tragic, we are fortunate that, thanks to the actions of our officers early this morning, more people were not injured or worse,” de Blasio said.

“The job our brave men and women perform on a daily basis to protect the people of New York City is often perilous and difficult, and we thank them for their service.”

The suspect was taken to Kings County Hospital, where he died.

In light of the attack, the NYPD plans to increase its presence at synagogues and other places of worship on Tuesday.

“So you will see some enhanced coverage in terms of police presence at these locations,” Miller said.