MALONE, N.Y. — A three-week manhunt that began with a brazen prison break involving stolen power tools and hacksaw blades hidden in frozen hamburger meat ended Sunday when a single state police sergeant spotted a suspicious man walking down a rural road near the Canadian border.

David Sweat’s capture came two days after his fellow escapee, Richard Matt, was killed in a confrontation with law enforcement while holding a shotgun. Sweat was unarmed when he was shot twice by Sgt. Jay Cook as the fugitive ran for a tree line.

Cook, a 21-year veteran, was alone and on routine patrol when he stumbled upon Sweat in the northern New York town of Constable, about 30 miles northwest of the prison, and recognized him. He gave chase when Sweat fled and decided to fire upon fearing he would lose him in the trees, state police said. The New York Times identified Cook as a firearms instructor.

“I can only assume he was going for the border,” said state police Superintendent Joseph D’Amico.

The arrest ended an ordeal that sent 1,300 local, state and federal law enforcement officers into the thickly forested northern reaches of New York and forced residents to tolerate nerve-wracking armed checkpoints and property searches.

“The nightmare is finally over,” Gov. Andrew Cuomo declared at a news conference.

Authorities said Sweat was struck in the torso and taken to a hospital in Malone before being transported by ambulance to Albany Medical Center, which has a trauma center. Sweat, who was listed in critical condition, was being evaluated by a team of doctors who would determine whether surgery was necessary, said Dr. Dennis McKenna.

Sweat had not been formally interviewed by investigators as of late Sunday, but any information he provides could be critical to the investigation of the escape, said Clinton County District Attorney Andrew Wylie.

Sweat will be charged with escape, burglary and other charges, Wylie said. He and Matt are suspected of breaking into some of the region’s many cabins during their time on the lam. Wylie said prosecutors would wait for Sweat to recover before charging him.

The men had been on the loose since June 6, when they cut their way out of a maximum-security prison in Dannemora using power tools. Two prison workers have been charged with helping them.

D’Amico said the men may have used black pepper to throw off the scent of dogs that were tracking them; he said Sweat’s DNA was recovered from pepper shakers found at one camp where the fugitives may have spent time.

“We did have difficulty tracking so, you know, it was fairly effective in that respect,” D’Amico said.

Cuomo said many questions remained unanswered in the case, including whether the inmates had other accomplices.

“We have already started a full investigation,” he said. “But today ends with good news. These were dangerous, dangerous men.”

Matt and Sweat used power tools to saw through a steel cell wall and several steel steam pipes, bashed a hole through a 2-foot-thick brick wall, squirmed through pipes and emerged from a manhole outside the Clinton Correctional Facility in Dannemora.

Sweat was serving a sentence of life without parole in the killing of a sheriff’s deputy in Broome County in 2002. Matt was serving 25 years to life for the killing and dismembering of his former boss.

Residents expressed relief Sunday that the killers were no longer on the loose.

“It’s a little unnerving, him being so close,” said Trevor Buchanan of Constable. “I’m just glad it’s over.”

In nearby Malone, Cathy Leffler cheered outside Alice Hyde Medical Center, where Sweat was taken by ambulance before being transferred. “I feel like I can sleep tonight,” Leffler said. “Life can go back to normal. It’s over now.”

The manhunt broke open Friday afternoon when a person towing a camper heard a loud noise and thought a tire had blown. Finding there was no flat, the driver drove eight miles before looking again and finding a bullet hole in the trailer. A tactical team responding to the scene of the shot smelled gunpowder inside a cabin and saw evidence that someone had fled out the back door.

A noise – perhaps a cough – ultimately did Matt in. A border patrol team discovered Matt, who was shot after failing to heed a command to raise his hands. He was shot three times in the head, according to an autopsy.

A coroner who attended the autopsy said Matt was clean, well-fed and dressed for the elements at the time he was killed.

Prosecutors said Joyce Mitchell, a prison tailoring shop instructor who got close to the men while working with them, had agreed to be their getaway driver but backed out because she felt guilty for participating in the escape. Authorities also said Mitchell had discussed killing her husband, Lyle Mitchell, as part of the plot.

Joyce Mitchell pleaded not guilty June 15 to charges that included felony promoting prison contraband, which authorities said included hacksaw blades and chisels.

Authorities said the men had filled their beds in their adjacent cells with clothes to make it appear they were sleeping when guards made overnight rounds. On a cut steam pipe, the prisoners left a taunting note containing a crude caricature of an Asian face and the words “Have a nice day.”

Prosecutors said the inmates apparently used tools stored by prison contractors, taking care to return them to their toolboxes after each night’s work.

On June 24, authorities charged Clinton corrections officer Gene Palmer with promoting prison contraband, tampering with physical evidence and official misconduct. Officials said he gave the two prisoners the frozen hamburger meat that Joyce Mitchell had used to hide the tools she smuggled to Sweat and Matt.

Palmer’s attorney said he had no knowledge that the meat contained hacksaw blades, a bit and a screwdriver. Palmer is due in court Monday.