Andi Traynor and Max Montgomery met each other on Facebook through mutual friends. They had gotten together casually and nonromantically a few times, then decided to go surfing early one morning on California’s Capitola Beach last October.

When they finished with the waves and were walking off the beach, Montgomery, 56, fell to the ground.

Traynor, a doctor, was confused for a moment. Then she checked and realized he did not have a pulse. He was having a heart attack.

“I saw him fall, and initially I thought he tripped,” said Traynor, 45, a medical professor at Stanford University and an anesthesiologist who works with high-risk pregnancies. “I turned him over, and I immediately realized something was very wrong.”

She yelled for someone to call 911 and then started CPR. She did a rescue breath and then chest compressions for seven minutes to keep his blood circulating before paramedics arrived. They used a defibrillator on him three times to no avail and then carried him to an ambulance.

She was distraught. She didn’t know at the time that videographer Alexander Baker had set up a time lapse video to record nature on the beach and that the entire frightening episode was being recorded.

“You can see me breaking down at that point,” Traynor said of the video. “I thought, ‘He’s dead, people don’t live through that.’ I can’t believe this just happened. How did this just happen? I just felt sadness.”

In the ambulance, paramedics used the defibrillator three more times and finally revived Montgomery.

Traynor said she was sure he had died and searched his Facebook to try to find his relatives to let them know. She contacted his sister and was flabbergasted to find out he was alive.

“His sister said, ‘He’s out of the procedure, do you want to talk to him?’ ” Traynor said. “I burst into tears.”

Montgomery, an outdoorsman and avid runner, got on the phone and apologized to her for collapsing. The next day he had triple bypass surgery.

Traynor showed up at the hospital and waited long hours with Montgomery’s family and friends. She had already developed a crush on him before the heart attack, and he had told her that he had a crush on her, as well. But their interaction had never been romantic, and they decided they’d take things very slowly. But seeing so many of Montgomery’s family and close, long-term friends together made her realize what a kindhearted good man her new friend was.

She was divorced with two kids and cautious to start a new relationship. He was divorced, as well.

“I saw so many amazing, lovely, kind people who loved him so much,” she said. “I’d spent some time studying what makes a healthy relationship, and one factor is somebody who has a good relationship with family and long-term friendships.”

After the surgery, which was a success, she went to visit his hospital room. He recalled telling her: “Who wants to be with a guy who had heart attack. I won’t blame you if you run for the hills.”

“I’m not going anywhere,” she told him.

For Montgomery, that was a turning point.

“When she said ‘I’m not going anywhere,’ I felt like my heart started to heal from the inside,” he said. “I had a great and fast recovery. I believe it was because I was madly in love.”

Six days later, after Montgomery was discharged from the hospital, they went back to Capitola Beach - and had their actual first kiss.

“We do consider the CPR our first kiss,” Traynor said. “But the day he got out of the hospital, we had our first real kiss.”

She told him there was footage of him falling to the ground and that the videographer had given it to him for his personal use. They decided together they wanted to use it to help people.

“We didn’t want to put it up on Facebook and say, ‘The craziest thing happened last weekend,’ ” Traynor said. “We wanted to be intentional about it.”

As their relationship grew stronger, they decided to educate people about the benefits of CPR and try to dispel some of the myths and fears. One of the biggest, Montgomery said, is people fear they will do more harm than good, and so they are hesitant to perform CPR, especially on a stranger.

To that, he points out that when someone doesn’t have a pulse, things can’t get worse for them, so it’s always worthwhile to give it a try.

They’ve started the Help-A-Heart foundation, which offers CPR instruction and outreach. It’s part of another nonprofit Montgomery founded, Paddle-4-Good, which offers adventure activities such as stand up paddling for underserved populations and people with physical and developmental needs.

Both Traynor and Montgomery are now certified CPR instructors and recite statistics from the American Heart Association: Every 90 seconds, someone dies somewhere in the United States from sudden cardiac arrest. Bystander CPR can triple the chances of survival. Most heart attacks outside the hospital happen at home, so if you learn CPR, you are most likely to use it on a family member and save the life of someone you love.

Since they started telling their story publicly, they have been on the receiving end of lots of bad jokes: “You have to get someone’s consent before you kiss them,” or “Some people will do anything to get a woman’s attention.”

They roll their eyes and chuckle politely. They don’t mind. Mostly, Montgomery said, he’s happy to be alive.

“It’s a crazy thing. It’s the craziest story of my life thus far,” he said. “I’m glad to be on the lucky side of it.”