The audience also included scores of police officers and other first responders. Crowds erupted in cheers as the cathedral emptied out at the end of the service, while others sang the national anthem.
Obama also stopped at a high school to thank a group of first responders and volunteers and met with patients recovering from the attacks at Massachusetts General Hospital.
"It was extremely uplifting for them," said Dr. David King, a trauma surgeon at the hospital. "I think it's incredibly inspiring that he would take time out and visit them and have a sincere interaction with all of these folks that have been hurt."
Obama "was humbled by the patients' bravery and their fortitude and their drive to continue," he added.
The first lady met with patients, families and hospital staff at Boston Children's Hospital and Brigham and Women's Hospital, the White House said.
The wounded: 59 still hospitalized
Investigators say the bombs, which exploded 12 seconds apart, were designed to deliver the most vicious suffering. A total of 59 people remained hospitalized on Thursday, six of them in critical condition, according to Boston-area hospitals. At least 13 people lost limbs as a result of the bombing.
One device was housed in a pressure cooker hidden inside a backpack, the FBI said. The device also had fragments that may have included nails, BBs and ball bearings, the agency said.
The second bomb was in a metal container, but it was unclear whether it was in a pressure cooker as well, the FBI said.
Photos obtained by CNN show the remains of a pressure cooker found at the scene, along with a shredded black backpack and what appear to be metal pellets or ball bearings. They were sent to the FBI's national laboratory in Virginia, where technicians will try to reconstruct the devices.
In the past, the U.S. government has warned federal agencies that terrorists could turn pressure cookers into bombs by packing them with explosives and shrapnel and detonating them with blasting caps.
Family and friends, meanwhile, were mourning the three dead:
• Richard, the 8-year-old boy with a gap-tooth grin and bright eyes. He loved to run and play in his yard.
• Campbell, a 29-year-old freckle-faced woman described by her mother as having "a heart of gold."
• Lu, the Chinese graduate student at Boston University who had moved to the city last fall, making friends and soaking up new experiences.
The U.S. State Department has been in contact with her family and the Chinese Foreign Ministry, Secretary of State John Kerry said in a statement released Thursday.
"We stand ready to provide whatever appropriate assistance we can to the family members of foreign nationals in the aftermath of this despicable act of terror," Kerry said.