Juliet Carty, 32, of Salem was across the street from St. James all alone holding three small flags.
"I just felt it was important to show support for somebody fighting for us overseas," she said. "It's truly sad ... I can't imagine what (his family) is going through."
"I'm the widow of a Marine," Grace Washburn of The Patriot Guard said outside the church. "I just want to do what I can for our fallen brothers and sisters and give them the respect they deserve for making the ultimate sacrifice."
A family friend, the Rev. Walter Waldron of St. Patrick's Church in Roxbury, was chief celebrant at the Mass. He was assisted by the Rev. John Sheridan of St. James, the Rev. Timothy Murphy of Immaculate Conception, and Norman LaPointe, a deacon at St. James.
Waldron described Ayube as a young man who fought evil with the greatest love a man can give, laying down his life for others.
"Jesus did it," Waldron said, "and James, in imitation of Him, did it. He laid down his life for his family, his friends and our country ... so that evil wouldn't win."
Ayube, who had previously done a tour of duty in Iraq, also was eulogized by Army Brig. Gen. Tim Trainor of West Point.
Trainor, who posthumously awarded Ayube the Bronze Star Medal on Friday, said the soldier posted the following quote on his Facebook page: "How can you come to know yourself? Never by thinking; always by doing ..."
"James came to know himself by performing his duty as a soldier, a loving son and a husband," the general said.
He said Ayube, a 2003 Salem High graduate, was "too young to have experienced all of life, but old enough to know he wanted to serve his country ..."
Ayube was buried in Harmony Grove Cemetery under a large white birch tree to the sounds of three rifle volleys, taps and final prayers.
Trainor presented American flags to Ayube's mother, Christina, who sat in a chair by the grave, and to Ayube's wife of two years, Lauren.
As the service ended, the young widow stood in dappled sunlight clutching the flag in her arms.