STOCKTON SPRINGS, Maine — Worshippers gave thanks Sunday for the tragedy that was averted when an armed gunman who took 11 Stockton Springs Elementary School fifth-graders hostage Friday was captured without a shot being fired.

The congregation of the Stockton Springs Community Church nodded in agreement when The Rev. Arthur Cotton asked them to “praise God for his protection of our kids and teachers this past week at school.”

The students were taken hostage at 8:30 a.m. Friday by Randall Hofland, 55, of Searsport. Hofland, who already was wanted by police and was the subject of a manhunt for allegedly pulling a gun on a Searsport officer during a routine safety check a week earlier, had entered the school armed with a semiautomatic handgun. Hofland was tackled by a state trooper a half-hour later when he released his hostages and stepped from the classroom after handing his gun over to one of the children.

Cotton said that a community has no warning of when events can change frighteningly and drastically because “when these things come, they come suddenly.” He said he found it difficult to believe that a person “would go to a school and perpetrate an act like that.”

“We thank God for watching over our school, our town, our children,” Cotton continued. “At least no one was physically hurt, although it obviously was a very emotional moment for the children, teachers and authorities.”

In closing his pastoral prayer, Cotton also asked the congregation to pray for Hofland.

“He obviously needs help,” he said.

After the service, Frank Costigan, great-grandfather of a first-grade student at the school, said he was stunned when he heard word of what was happening that morning. He said news of the gunman at school spread like wildfire through town. Families were aware of the situation within moments, he said. Costigan said he rushed to the school to find his great-granddaughter, but the police already had surrounded the building and sealed off the area.

Costigan said his 7-year-old great-granddaughter, Camas, who was with him at church, later told him she knew something was wrong because the school had practiced its Code Blue lock-down procedure in the past. The school enacted the lockdown once it learned Hofland was in the building, and students were evacuated onto buses and removed to Searsport Elementary School after the hostages were released.

“She knew something was up,” Costigan said of his grand-daughter. “When she heard Code Blue, she knew there was a problem.”

Another first-grade parent, Ken McGray of Searsmont, said his son was told the class was going on a field trip to Searsport.

Stockton Springs parent Ron Jackson, whose daughter was one of the hostages taken by Hofland, said parents were advised by the authorities against talking to the media about their children’s ordeal. Jackson said Saturday that he did not want to have his daughter relive the experience because she already had been through such a wrenching situation.

At 10:50 p.m. Thursday, Oct. 23, Searsport police were conducting a seat belt safety check and attempted to inspect Hofland’s vehicle. An officer approached his car and at that point he brandished a handgun, then drove a few hundred feet down Route 1 to his driveway and ran into the woods. Police shut down the highway between Searsport and Prospect but were unable to locate Hofland.

Schools in SAD 56 were closed the next day as a precaution, and safety procedures limiting access to them were put in place when they reopened last week. The plan was still in place Friday morning.

Police said Hofland was first observed in the cafeteria that morning by a parent visiting the school. The parent alerted the office, and a bus driver ran to the classroom and confronted him. At that point, Hofland displayed his handgun, walked down the hall and entered the fifth-grade classroom.

The school immediately locked all the students in their respective classrooms until police arrived. Once police had secured the classroom where Hofland was holding the children, the others were removed from the school and placed on buses. Hofland released two of his hostages at some point during the confrontation, and nine remained inside with Hofland as state police Detective Jason Andrews began talking to him from outside the doorway. When Hofland let the other nine go, Andrews tackled and arrested him as he walked from the classroom.

Department of Public Safety spokesman Stephen McCausland said Sunday that detectives had yet to determine how Hofland gained access to the school and what he planned to do once inside. He said that detectives had attempted to speak to Hofland about his motives, but that he did not know how extensive their discussions were.

An acquaintance of Hofland, Paul M. Clements, founder of Dads Against Divorce Discrimination, formerly of New Hampshire but now retired to Gaffney, S.C., speculated that Hofland may have wanted to see his son.

In an e-mail sent Sunday, Clements said he met Hofland in New Hampshire a decade ago. He said Hofland had been engaged in a lengthy court dispute with his former wife over visitation rights. When she moved to Maine some years ago, Hofland followed to be close to his son, he said.

“Please understand that I do not write in support of Randall Hofland or what he did. We abhor such extreme, unlawful behavior. The fatherhood movement suffers because of it,” Clements wrote. “We are interested in making the public aware of the abuse of fathers by the family court system, and this is a good example of the extreme emotions and consequences which can derive from that abuse. … Like most fathers, he found that the courts were unresponsive to his pleadings, no matter how sound or settled in law.”

McCausland said Sunday he had no knowledge of whether a child of Hofland’s was a student at the school. After his arrest, Hofland was taken to Waldo County Jail and booked on a charge of aggravated criminal threatening with a dangerous weapon filed after the Searsport incident a week ago.

McCausland said Hofland was scheduled to appear on that charge in either Belfast District Court or Waldo County Superior Court on Monday. He said District Attorney Geoffrey Rushlau could add other charges dealing with Friday’s hostage-taking during that appearance.