NEW YORK -- Shalane Flanagan dethroned Mary Keitany on Sunday and became the first American woman to win the New York City Marathon since 1977, potentially ending her decorated career with her first major marathon victory.
Geoffrey Kamworor of Kenya won the men's race, holding off countryman Wilson Kipsang by 3 seconds for his first major victory.
Keitany had won three straight New York marathons, but Flanagan pulled away from the Kenyan great with about three miles to go. Flanagan finished in 2 hours, 26 minutes, 53 seconds, about a minute faster than Keitany.
The American cried and yelled as she approached the finish line all alone.
"It's indescribable,'' said Flanagan, 36. "It's a moment I'm trying to soak up and savor.''
The last American woman to win New York was Miki Gorman, who took consecutive titles in 1976-77.
Flanagan finished second in New York for her first marathon in 2010 but hadn't run this race since. This was her first marathon since finishing sixth at the Rio Games due to a fracture in her lower back. The injury kept her out of the Boston Marathon in the spring but set her up to train hard for New York with an eye on Keitany.
Flanagan had called Keitany "the alpha racer'' and said she was ready to "suffer dearly'' while keeping pace with the unpredictable Kenyan.
Flanagan, Keitany and Ethiopia's Mamitu Daska were step-and-step until the 24th mile. Keitany never made a move, though, and Flanagan hit the jets to pull away, keeping a stern face until getting emotional near the finish in Central Park.
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.
Kamworor edged Kipsang with a time of 2:10:53. Kamworor separated from the pack late and seemed like he would cruise to his first major marathon victory, but Kipsang appeared on his heels in the final stretch.
Kipsang, 24, didn't have enough to catch Kamworor, though. The winner kissed the pavement right after crossing the finish, then turned to embrace Kipsang.
American running great and 2009 New York winner Meb Keflezighi completed his 26th and final marathon in 11th place at 2:15:29, collapsing as he crossed the finish.
"Thank you, New York, for showing up today,'' Keflezighi told the crowd. "Cheering me on and showing that vibrant energy.''
More than 70 friends and family were on hand to witness the final bow of the only runner to win an Olympic medal and the New York and Boston marathons. Keflezighi became a U.S. citizen in 1998, a decade after his family left war-torn Eritrea.
In 2009, he became the first American man since Alberto Salazar in 1982 to win the NYC marathon.
"What a day for America,'' Keflezighi said. "I heard [Flanagan] won at 24 [miles]. I think I did a jump with both hands in the air.''
NYC marathon race director Peter Ciaccia called this "the Mebathon.'' He surpassed the great Grete Waitz of Norway with his 11th appearance here. Throughout his career, Keflezighi has produced eight top-10 finishes in New York.
The race went off without interruption five days after the bike path terror attack killed eight in lower Manhattan. Police had promised an unprecedented effort to secure the course, a plan including hundreds of extra uniformed patrol and plainclothes officers, roving teams of counterterrorism commandos armed with heavy weapons, bomb-sniffing dogs and rooftop snipers.
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.''
Beverly Ramos ran the race with a Puerto Rican flag headband two months after her home island was ravaged by Hurricane Maria. Like many in Puerto Rico, Ramos was without power after the storm. Still, she decided to continue training near San Juan, seeking out safe places to run amid the wreckage.
"You have to stay strong no matter what,'' Ramos said. "A lot of runners encouraged me to continue and to push.''
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.