Shalane Flanagan became the first American woman to win the New York City Marathon on Sunday since 1977, pulling away from Mary Keitany in the last three miles of the race for her first major marathon victory.

Keitany had won three straight New York marathons, but Flanagan pulled away from the Kenyan great with about three miles to go and finished with an unofficial time of 2 hours, 26 minutes, 53 seconds, about a minute faster than Keitany.

The last American woman to win New York was Miki Gorman, who won consecutive titles in 1976-77.

Flanagan cried and yelled as she approached the finish line all alone.

"It's indescribable," the 36-year-old Flanagan said. "It's a moment I'm trying to soak up and savor."

NEW YORK CITY MARATHON FEATURES MASSIVE SECURITY EFFORT AFTER DEADLY TRUCK ATTACK

Flanagan finished second in New York in her first marathon in 2010 but hadn't run this race since. After a fracture in her lower back kept her out of the Boston Marathon, Flanagan trained hard for New York with an eye on Keitany.

Flanagan called Keitany "the alpha racer" and said she was ready to "suffer dearly" while keeping up with the unpredictable runner.

On the podium, Flanagan put her hands over face and began to cry again when she was announced the winner. She turned to hug Keitany before accepting her medal.

"This is the moment I've dreamed off since I was a little girl," Flanagan said.

Flanagan had said she may retire if she won New York. She didn't immediately make an announcement regarding her future.

For the men's competition, Geoffrey Kamworor of Kenya held off countryman Wilson Kipsang by three seconds for his first major victory at the marathon.

Kamworor ran the race in 2 hours, 10 minutes, 53 seconds. He and Kipsang embraced just past the finish line to huge cheers.

The race on Sunday took place just days after a truck attack in Lower Manhattan killed eight people, and took place under the watchful eye of an extremely heavy police presence.

In Brooklyn, where runners made their way down a long stretch, roads were blocked and officers lined the street. As the runners went by, they were accompanied by an escort of police vehicles.

Those cheering the runners on say the increased security presence was noted, but didn't dim the experience.

Karen Hester has been coming to watch the race for 10 years and told the Associated PRess she was "not in the slightest" bit concerned about being in a crowded space or the threat of a terror attack.

Mayor Bill de Blasio said the city was expecting 2 million fans to line the course.

"New York City said strongly we're not giving into terrorists," de Blasio said, adding "That's a message we're sending the whole world."

Comedian Kevin Hart made his marathon debut at New York. Forget about chasing gold — the actor and fitness nut was mostly worried about avoiding humiliation.

"I don't want to see a bunch of memes of me looking weird out here," Hart said shortly before starting.

The Associated Press contributed to this report.