STOCKTON SPRINGS, Maine — A school hostage situation ended peacefully Friday morning when the armed gunman who fled from police last week released 11 fifth-graders he had threatened in a classroom and surrendered to authorities.

“The kids are doing well. Obviously, it’s a stressful situation but they are doing well,” Maine State Police Lt. Gerard Madden said from outside the Stockton Springs Elementary School on Church Street in this small Waldo County town. “No shots were fired.”

He said the students were shaken by the incident.

The gunman, Randall Hofland, 55, of Searsport, had been the subject of a police manhunt for a week before he showed up at the school at approximately 8:30 a.m. Friday. Hofland had pulled a gun on a Searsport police officer on Oct. 23 during a seat belt safety check and fled into the woods near his home, which is located about a mile from the school. Police had not received any reports of sightings of Hofland since then.

Police said that a parent at the school first noticed Hofland in the cafeteria attempting to coerce two children into a restroom and immediately notified the school secretary. The secretary told a bus driver, who went to the cafeteria and confronted Hofland.

Upon being confronted, Hofland reportedly brandished a semiautomatic handgun and walked down the hall and entered the fifth-grade classroom. There were 11 pupils and at least one teacher in the classroom initially, but Hofland allowed two youngsters to leave. Police were not immediately sure why those two were released.

Madden said the school had a plan in place for such a situation and immediately locked down the school. The pupils who were not held hostage were ushered onto a school bus. Once the others were released, they too were put on the bus, and all were taken to Searsport Elementary School where they were reunited with their teachers and received counseling.

A school official said everything happened so quickly, there was no time to notify parents during the incident. But news of the gunman spread through the town like wildfire, and parents began showing up at the locked-down school. Police directed the parents to the Searsport school. Police said all parents were cooperative.

The school secretary notified the Waldo County Communications Center of the situation at 8:37 a.m. and police from all over the county rushed to the scene. The school, which houses 85 students and 11 teachers and staff, was surrounded and secured.

Nine students remained in the classroom with Hofland when state police Detective Jason Andrews began communicating with the gunman through the door from out in the hallway.

Within minutes Hofland handed his loaded gun to one of the students in the classroom and walked out into the hallway where he was tackled by one of the waiting officers, according to police. Detective Andrews, Trooper Jonah O’Roak and Waldo County Sheriff’s Deputies Scott Jones and Glenn Graef placed Hofland in custody at 9:08 a.m.

One officer at the scene said Hofland looked “scruffy and unshaven” and that his pants were ripped. Madden said Hofland had made statements to the arresting officers but declined to elaborate on what was said.

“He was saying lots of things; he was talking about different things,” Madden said.

Madden said police were trying to determine Friday afternoon where Hofland had been for the past week, how he got into the school, and what his intentions were there.

“To the school’s credit, they had a plan and locked down the school,” Madden said. “Credit to the officers that arrived and credit to the school’s safety plan.”

Stockton Springs Elementary School is clearly visible from Church Street, a spur off Routes 1 and 1A, and is located in a residential area. Across the road from the school are a couple of houses and a church, and residences are on either side of it. A fence encloses the playground area of the school property. A sign advertising a pie festival scheduled for Friday afternoon after school was displayed prominently on the grounds.

Specific details on the school’s security measures were not available Friday.

Although Hofland was known to local police, he had no criminal record in Maine until he displayed a handgun to a Searsport officer at approximately 10:50 p.m. Thursday, Oct. 23, when he was stopped at a safety checkpoint. After showing his weapon, Hofland drove off and turned into his driveway a few hundred feet from the checkpoint. Police shut down U.S. Route 1 between Searsport and Prospect, but were unable to find him. Schools in Stockton Springs, Searsport and Frankfort were closed the next day as a precaution.

Though Hofland did not have a record, he was being investigated for allegedly taking more than $100,000 in money and property from retired sea Capt. George Perkins of Stockton Springs. Belfast private investigator Gary Boynton had been retained by Perkins to assist him in recovering his property and prosecuting Hofland. Boynton said Friday that he had been working with the Attorney General’s Office on the case. Boynton said Hofland had worked for Perkins for the past four years and had gained his trust during that time.

“I’ve been working with Captain Perkins on this for more than a year,” Boynton said. “Hofland took advantage of a man who was very ill.”

Hofland was charged Friday with criminal threatening with a dangerous weapon for the Oct. 23 incident. Police and prosecutors were meeting to discuss charges related to the hostage situation.

Gov. John Baldacci praised school and police personnel for their fast response on Friday. He said the school secretary called a “code blue” and then dialed 911.

After being locked down on Oct. 24, the day after the traffic incident, the schools have been in a state of heightened security, Baldacci said.

Details of the school’s emergency plan weren’t immediately available, but SAD 56 Superintendent Raymond Freve said they included a code that was broadcast on the intercom to advise teachers of a serious situation and classrooms had to be locked down.

“Everyone was calm. They did what they were supposed to do. The bottom line: Nobody got hurt,” the superintendent said.

The Maine Department of Education began requiring schools to enlist local police, fire and emergency preparedness officials in creating emergency response plans in 2002.

The school in the small coastal town 10 miles north of Belfast serves kindergarten through fifth grade. Some pupils were traumatized by the incident, Freve said, and the school district has scheduled counseling sessions and meetings with parents on Saturday.

As for Hofland, he had lived in the area for about seven years, most recently in a trailer off a dirt road, Searsport Police Chief Dick LaHaye said.

Police had not had previous contact with Hofland, but LaHaye was aware of reports that Hofland may have posted comments on an Internet message board questioning whether police had the right to stop motorists at roadblocks.

“You might be able to draw the conclusion that he might have issues with those types of actions,” LaHaye said.

Hofland once appealed a parking ticket he received in Concord, N.H., to the Supreme Court of New Hampshire.

He claimed his constitutional rights were violated because the city didn’t have signs that provided notice of a city ordinance prohibiting parking on city streets for more than 30 minutes between 2 a.m. and 6 a.m. The court rejected his appeal.

The New England Coalition to Prevent Gun Violence commended the police for averting tragedy Friday. Director Cathie Whittenburg noted that each year more than 30,000 Americans are killed by firearms and said she was relieved that the situation ended peacefully.

“We are very thankful that Hofland chose to end the hostage situation,” she said. “This situation could have ended in tragedy had Hofland chosen instead to use his gun.”

The Associated Press contributed to this report.