Randall Hofland, 55, had released all the students and had turned over a loaded gun to one of the young hostages before he was arrested at Stockton Springs Elementary School, authorities said.
He was taken to jail and all of the school's pupils, about 80, were taken by bus to an elementary school in neighboring Searsport.
"These children are very brave. They did a tremendous job," Gov. John Baldacci said.
The gunman walked into a fifth-grade classroom in the small coastal town around the start of the day. State police were called at 8:42 a.m. and Hofland was arrested about 20 minutes later after he was tackled by a state trooper.
Hofland was the object of a manhunt that began on the night of Oct. 23 after he allegedly pointed a gun at a police officer who stopped him during a seat belt safety check in Searsport. Hofland drove off, eventually abandoning his car in a field.
A two-mile stretch of U.S. 1 was closed to traffic for a time during the search, which involved more than three dozen police officers, including the state police tactical team. Schools in School Administrative District 56, including Stockton Springs Elementary School, were closed for the day after Hofland fled, out of concern for students' safety.
Hofland was charged Friday with criminal threatening with a dangerous weapon in the Oct. 23 traffic stop. Police and prosecutors were meeting to discuss charges related to the hostage situation.
Baldacci praised school and police 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 stop, the schools have been in a state of heightened security.
Details of the school's emergency plan weren't immediately available, but district school Superintendent Raymond Freve said they included a code broadcast on the intercom to advise teachers there was 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," Freve 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 district has scheduled counseling sessions for students and meetings with parents Saturday.
Hofland had lived in the area for about seven years, most recently in a trailer off a dirt road, Searsport Police Chief Dick LaHaye said. LaHaye said he 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.
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.