As leaders of church and state bade John Cardinal O’Connor a majestic goodbye at St. Patrick’s Cathedral yesterday, hundreds of ordinary New Yorkers prayed outside, some kneeling on the scorching sidewalks.

The streets across from the cathedral on Fifth Avenue and on 50th Street turned into an open-air church as mourners without tickets to get inside ignored 90-degree heat and lined up eight deep behind police barricades.

The soaring music and heartfelt prayers inside the cathedral were broadcast outside on loudspeakers and many who gathered outdoors joined in to celebrate the Mass.

A few dropped to their knees on the scorching concrete sidewalks and worshipped aloud.

“I wanted to be here so the world will have some idea how many people loved him and how many followers he had,” said Victor Velazquez, 39, clutching a brown-beaded rosary.

“Everyone out here loved the man and I loved him very much,” said Velazquez, a building-maintenance worker from Queens.

“This is a beautiful experience and I wanted to be part of it,” said Steve Hanson, a Manhattan accountant who knelt on the sidewalk and offered his prayers.

“I want to honor this man,” he said. “He had so much humility and patience. I came here to pray for him and celebrate his life. All I can do is pray. He is with the Lord now.”

Strangers turned to each other on the streets and shook hands as a sign of peace during the liturgy and reached out to hold hands with those next to them during the reciting of the Our Father.

Volunteers with the Red Cross and Salvation Army manned tables with huge water containers, and also gave out cups of lemonade and water to those determined not to leave despite the searing heat and crowds.

“I don’t care how hot it is or how crowded it gets,” said Maria Rodriguez, 43, a Bronx nurse, who brought a bunch of daisies to leave outside the cathedral.

“I’m here because I feel it’s important to be here,” she said. “O’Connor did so much for so many people that the least I can do is to be here to pray and say goodbye.”

Maria Esposito, a Bronx mom who brought her 6-year-old son, said it was important for young people to be there.

“O’Connor was someone I want my son to know about,” she said. “Coming out here is all about that and paying my final respects to a great leader who had kind words for us all.

“He was an example to all and I want my son to remember that and this day,” said Esposito, 37.

Louis Maresca, an account manager from Brooklyn, wiped tears from his reddened eyes and said he was drawn to the funeral because of the kind of man O’Connor had been.

“I always thought he only represented the rich and mighty, but in the past few days I discovered he was much more than that. That is why I’m out here,” he said.

“I learned how much he did to bring the Jews and Catholics together. There are too many divisions in the world today, so if a person can join two huge religions together, it says something about his character,” Maresca said.

Bill House, 65, of Massachusetts, said the cardinal “reminds me of how evil abortion is. I like the things he stands for. He was not afraid of controversy. I think people know that he cares about them even though they disagree on some issues.”

Pat Lim, a Brooklyn architect, said she was there because she felt O’Connor was “the best human being you could find in America.

“You don’t find too many people like him,” she said. “He went to every corner of the world to help the human mind.”