As it does during similar large-scale events, the Philadelphia Fire Department had dispatched special emergency-response teams to locations along the marathon route.
Members of one of the five teams on call Sunday saw Lee collapse and rushed to him, said Mark McDonald, spokesman for Mayor Nutter.
"Finish lines are one of the most significant hot spots, where people are going to really pour it on," McDonald said.
Lee was a senior nursing student from Cerritos, Calif. It was not clear whether he had experience in marathons. He finished the 13-mile race in 1 hour, 58 minutes.
Robin Sullivan saw paramedics rush to him.
"I saw the stretchers; I wasn't sure what was going on," said Sullivan, whose husband, Mark, has run in 18 Philadelphia Marathons. "My friend and I were standing there watching and saw the stretchers and immediately thought it was something serious."
Students gathered on the Penn campus Sunday night to remember Lee. The university e-mailed students offering counseling services.
According to McDonald, the second victim also collapsed close to a rescue team. Paramedics rushed him to the hospital, where he died. Nutter later met with the man's widow at the hospital, McDonald said.
A police spokeswoman said both men appeared to have suffered heart attacks.
Cardiologists said that was unlikely, particularly with a 21-year-old victim. More plausible, they said, was that the younger man, and maybe the 40-year-old runner, had undetected heart problems that were exacerbated as their blood-sugar, potassium, and sodium levels dropped drastically during the race.
"I keep telling people, if they're a runner, they should, in fact, get a checkup and make sure they understand their risks," said Alfred Bove, a Temple University cardiologist who has run marathons.
Unlike some races, the Philadelphia Marathon is open to any entrant over age 16. The Boston Marathon, for one, requires entrants to qualify on the basis of past performance.
The Philadelphia course is flat, with open spaces and a scenic route, starting and finishing on the Benjamin Franklin Parkway a few hundred yards from the Art Museum.
Bob Schwelm, founder of a Bryn Mawr running club, said the popularity of the marathon - and its open registration - had drawn more runners each year, including those who were not prepared for a 26-mile run.
From his spot at Mile 20 on Sunday, Schwelm noticed participants eating brownies, half-jogging, and texting on their smartphones. He also saw people wearing long sleeves and tights on a day the temperature climbed into the 60s.
"What we noticed in the back were how many of these people were overdressed," he said.
Organizers and some participants said the conditions were ideal. Other runners, such as Peter Radford, said a slightly cooler day would have been better.
Radford, a Harleysville resident, has run nine marathons and said some participants don't appreciate how much training it requires.
"There are people - we call them 'weekend warriors' or 'bucket-list people' - who we do worry about, because they sometimes enter marathons without enough training," said Radford, who belongs to a running group. "Serious marathoners train for 16 to 18 weeks for a marathon."
Said Mark Sullivan, another veteran runner: "It's a terribly sad thing whenever someone dies. . . . But running is not something people should be afraid of."
Contact staff writer John P. Martin at 215-854-4774, firstname.lastname@example.org, or @JPMartinInky on Twitter.