ROCHESTER — After an overnight standoff with gunshots fired at law enforcement officials, police took a homeless Rochester man into custody on Monday morning.

Christopher Thomas, 27, was apprehended after he packed up his campsite and attempted to leave the woods behind Walmart and The Ridge shopping plaza on Farmington Road. He was arrested around 10:20 a.m.

The encounter with police began Sunday afternoon after someone reported a man with a rifle spotted in the rear parking lot of Walmart; he then went into the woods. Walmart and stores at The Ridge were evacuated for safety reasons.

Police Chief Paul Toussaint said Thomas fired on police overnight.

“Throughout the night, we did rely heavily on units from state police aviation unit as well as the Mass. state police aviation unit to keep eyes on the suspect,” Toussaint said during a news conference Monday at the Rochester Police Department after the arrest. “We did, on more than one occasion, face gunshots from the suspect into the area of the helicopter and police officers.”

Toussaint said police had been looking for Thomas for some time. He was facing charges for criminal threatening and theft.

The criminal threatening charges stemmed from when Thomas lived at Northgate Apartments in Rochester, which is not far from The Ridge.

Toussaint said the theft charges relate to incidents at Market Basket and Walmart. He said police do not yet know how Thomas obtained the gun.

Toussaint said Thomas will also be charged for firing a firearm at law enforcement officials.

New Hampshire State Police Col. Christopher Wagner also spoke at the news conference.

“There were some very tense moments throughout the night, but thanks to the hard work and discipline and dedication of all those officers who were out there last night — that is what made this successful,” Wagner said.

Wagner said due to high-tech equipment on state police helicopters from Massachusetts and New Hampshire, authorities were able to pinpoint Thomas’ exact location.

“Night vision, infrared, so the helicopters can pretty much fly in the dark without being seen or detected. They can be heard, certainly, but that gave us the advantage to watch every bit of his movement,” Wagner said.

Wagner said once Thomas began to move Monday morning, officers were arrested him.

More than 70 law enforcement officers from New Hampshire, Massachusetts and Maine participated in the capture, Wagner said.

Thomas is being held without bail and is scheduled to be arraigned this afternoon at Strafford County Superior Court in Dover.