Avi Hatami had his ear buds in, studying for a medical exam.

He didn’t hear the first call for medical assistance on the 7:49 a.m. Long Island Rail Road train out of Syosset.

When another announcement came about a minute later, the aspiring doctor pulled out the buds and listened.

Hatami, who graduated from medical school in Mexico 10 months ago, dashed to the next car.

He found a man collapsed in his seat. He had no pulse. He was not breathing. His eyes were dilated. He was cold and sweating. The color of his face was “bluish.”

“I thought, ‘This man is dead.’ Either he is dead or I will bring him back,” Hatami recalled.

“I was very nervous. First patient in the States. I don’t have a license yet. I’m 23 years old. I think I was one of the youngest people on the train,” Hatami said.

With the help of another passenger, Hatami put Brad Wieboldt, 51, on the floor, tore off his jacket and shirt, and started performing CPR, pressing down on his chest.

“I was yelling, ‘Stay with me, stay with me, come on, come on, stay with me,’ and just kept on going,” Hatami said.

Soon, some color returned to Wieboldt’s face. A crowd aboard the train had surrounded the scene, and people started cheering and urging Wieboldt to hang on, Hatami said.

“The people could see his color coming back, so they got excited, they got happy,” Hatami said.

But he knew Wieboldt, who was heading to his job as director of marketing at Fordham Law School, was still near death. With the help of a retired nurse also on board, he continued the CPR for at least 15 minutes, until the train finally pulled into Westbury.

Nassau County police EMTs came aboard and took over, shocking Wieboldt’s heart several times to keep him alive and continuing CPR. Hatami backed away, letting them do their job.

As he watched Wieboldt carried away on a stretcher, he still didn’t think he would survive.

“I called my dad and I was like, ‘I don’t think this guy is going to make it.’ None of us did,” Hatami said.

Wieboldt was taken to NYU Winthrop Hospital in Mineola, where doctors treated him for a heart attack. To save him, they had to place him in a medically induced coma for several days. They also put in two stents to restore his blood flow.

Wieboldt did survive. He woke up five days later, on his 51st birthday, March 23, though he remembers nothing of what happened. He was released from the hospital and doctors say he is doing well.

For days, Wieboldt, of East Norwich, did not know the identity of the medical student who saved him. But after Wieboldt’s story appeared in the news, the two connected through a mutual friend who posted one of the stories on social media.

They met face-to-face for the first time, on the platform of the LIRR station in Syosset where they both had boarded the train March 18.

They hugged. Wieboldt thanked Hatami for saving his life. In Mexico, Hatami said, he performed CPR 20 times on people in emergency rooms as part of his training.

“Without Avi,” Wieboldt said during the meeting, arranged by Winthrop, “there is just no question I wouldn’t be here.”