It was a miracle on Runway 31L.

Frightened passengers braced for a crash landing at Kennedy Airport today when the nose gear failed on their flight from Rio de Janeiro.

But the gear on the Airbus A330 amazingly locked into the correct position as the plane was just 50 feet above the runway.

“It was like the hand of God turned the wheel,” said a Port Authority rescuer who was part of the disaster response crew put in place for the incident.

None of the 190 people aboard TAM Airlines Flight 8078 were hurt — despite getting the fright of their lives.

“Everyone was panicking inside the plane,” said Rio resident Anna Maria Falcao, 33.

“Even the crew was running around panicking, saying ‘Don’t worry, no one’s going to die.’ So many people were crying,” said Falcao, who was traveling to New York with her 1-year-old son, her husband and her mother.

Everyone was warned to brace by putting their heads in their hands, Falcao said.

“The captain kept saying ‘Be calm, keep calm. We know what we’re doing,’” said Matheus Freiha, 23, of Sao Paulo.

But the emergency preparations proved unnecessary — the landing turned out to be smooth as silk, and passengers’ fright turned to applause for the skillful flight crew.

“It was a perfect landing, better than normal,” said Freiha, who is in New York to study at the International Culinary Center.

The plane landed without incident at 11 a.m., after circling the airport twice so controllers and rescuers could get a look at its nose gear.

The nose gear dropped down, but the wheels were turned at a right angle. “It appears cocked at 90 degrees,” a controller radioed one of the pilots.

The incident recalled JetBlue Flight 292, an Airbus which had a similar problem with its landing gear when it made an emergency landing at Los Angeles in September 2005.

But unlike today’s incident, the JetBlue A320’s landing gear never straightened out. The twisted gear created a shower of sparks as the plane skidded to a stop.