A deranged passenger aboard a New York-bound Delta plane tried to break into the cockpit Wednesday while shouting that he is God – but flight attendants aided by passengers tackled and restrained the lunatic.

Carlos Ramírez, 30, tried to barge into the cockpit of Flight 579, shouting, “I am God! Tomorrow San Juan is going to disappear!” Puerto Rican authorities said.

“I came to save the world, and I’m going to end terrorism!” the man also yelled before members of the cabin crew overpowered him with the assistance of a few brave passengers.

Ramírez’s outburst on the Boeing 737-900ER shortly after takeoff forced the pilots to return to San Juan, where police took him into custody.

The roughly 160 passengers waited at the gate before the flight took off again for JFK, where it landed at 1:10 p.m., more than two hours late, Delta rep Michael Thomas told The Post.

Several rattled passengers described the drama, which left some in tears, after their arrival in New York.

Moraima Garcia Rohena, a psychologist vacationing in the Big Apple, said the plane was still climbing after takeoff when the man got up and walked toward the front.

“When he got to the middle of the plane the flight attendants tried to stop him. They said, ‘Stop! Stop! You cannot be walking,’” Rohena told The Post.

“He didn’t stop, he continued. The flight attendants — three of them — stood up and told him he cannot be there. They told him, ‘You need to back off!’ He started saying that he was God and he was preventing a catastrophe on the plane,” she said.

“Then he tried to open the cockpit door. He banged on it but he couldn’t get it open,” she added. “The passengers restrained him. One of the flight attendants went to the back to get something to restrain him. The passengers held him down.”

Another passenger, Aereida Diaz, 31, a pharmaceutical worker who was traveling to New York to visit her father, said the incident reminded her of the 9/11 hijackings.

“I thought it was a terrorist attack. I always think the worst when something like this happened in a plane after 9/11,” Diaz said.

Jacob Colon, a 24-year-old warehouse worker from Brooklyn who went to Puerto Rico to celebrate his girlfriend’s birthday, said he “caught a little panic attack.”

“I was about to beat up the guy myself. He delayed our flight. He gets on the plane. He starts talking about Jesus this, the world was going to end and the plane was going to crash — just another fool,” he said.

“This is only my second time on a plane. … I’ve never been on a plane like that and to hear that, my first reaction was to get angry. My second reaction was to worry. I got to go back home to my mother and my siblings,” Colon continued.

“One thing I do want to give to Delta is they were able to turn that plane around real fast,” he added.

One couple decided to stay behind in San Juan and wait for another plane.

“One lady, she and her husband, they didn’t get back on the plane. They were so scared they ended up taking another flight,” said Estela Llanes, who went to Puerto Rico to celebrate her 20th birthday.

“We were all pretty nervous. Nobody knew what to do. Everybody was jumping up out of their seats trying to figure out what was going on,” she said.

Thomas, the Delta spokesman, said the cockpit’s door remain locked and secure during the incident and that earlier reports that the captain arrested the suspect were inaccurate.

“Delta applauds the quick action and professionalism of the crew of Delta flight 579,” the airline said in a statement.

The FBI has launched an investigation, but spokeswoman Limary Cruz-Rubio said she did not have additional details.