Keitany, victor of this year's London Marathon and the fastest ever in a women's only marathon, had been expected to run away with the race but a slow pace allowed Flanagan and others to stay with her early.
It had been 40 years since an American won the women's field of the New York City Marathon. Kenyan Mary Keitany, who had won in NY in each of the past three years and set a world record in April, finished second.
Kipsang, the 2014 NY champion, was three seconds back with Ethiopia's Lelisa Desisa third in 2:11:32.
In men's event, Kamworor held off compatriot Wilson Kipsang's challenge to win at a time of 2:10:53.
"This is a moment I've dreamed of since I was a little girl", the 36-year-old Flanagan said. She was also the 10,000m runner-up at the 2008 Beijing Olympics.
Flanagan previously finished second in the 2010 NYC Marathon. Lelisa Desisa of Ethiopia was third at 2:11:32.
Snipers were present in heightened security measures after the Manhattan truck attack which killed eight people.
Manuela Schaer stunned five-times champion Tatyana McFadden in the women's race, defeating the American by nearly three minutes in 1:48.09.
Only one other women's race runner - Norway's Grete Waitz - can claim that achievement, with five consecutive wins.
Keitany was seeking to cap a career year, in which she won the London Marathon with a blistering time of 2:17:01, a women's-only record.
Unlike last year's men's wheelchair race which came down to a photo finish and six hundredths of a second, Marcel Hug of Switzerland defended his title by a whopping 2 minutes, 19.82 seconds over John Charles Smith of Great Britain.