After a weeks-long manhunt culminating in a desperate chase across a field less than two miles south of the Canadian border, the second of two convicts who orchestrated a brazen escape from a New York prison was shot and taken into police custody Sunday afternoon.

It was 23 days since the convict, 35-year-old David Sweat, had hack-sawed his way out of his maximum security cell with fellow inmate Richard Matt. Matt, 49, was shot and killed by police on Friday.

“The nightmare is finally over,” Gov. Andrew Cuomo (D) declared at a news conference. “These were really dangerous, dangerous men.”

The saga that has gripped the region for the past three weeks ended the way it began, with a scene straight from a Hollywood script.

Officials said Sgt. Jay Cook, a firearms instructor patrolling alone on a rain-drenched road near the border, stopped to question a strange man jogging along the shoulder. He recognized the man as Sweat and told him to come over — instead, the jogger broke into a run and attempted to dash across an open field and into the cover of trees on the other side.

Cook gave chase and eventually fired on Sweat, shooting him twice in the torso. Sweat was unarmed.

A New York State corrections officer smiles and waves to a passing motorist Sunday, June 29, 2015, along State Route 30 in the town of Constable, N.U., after David Sweat was shot and captured. 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 State Police Sgt. Jay Cook as the fugitive ran for a tree line. (Jason Hunter/Watertown Daily Times via AP)

“He realized that Sweat was going to make it to a tree line and could have possibly disappeared,” New York State Police Superintendent Joseph A. D’Amico told reporters Sunday. “… I think he did a very courageous and brave act of policing.”

The injured Sweat was taken to a local hospital and then to Albany Medical Center, where he is said to be in critical condition.

The exhaustive manhunt for Sweat and Matt broke open two days ago, when state police received a call from a civilian who said someone had shot at a trailer he was towing as he drove by. That led police to a cabin in Malone, N.Y., not far from Constable, where they smelled gunpowder and saw signs that the cabin had only recently been abandoned.

A cough gave Matt away. A tactical team zeroed in and found the escapee, who was armed with a 20-gauge shotgun, according to police. When he refused to surrender, Matt was shot and killed.

There was no sighting of Sweat at the site, but, D’Amico said Friday, there was also “no indication that Sweat wasn’t accompanying Matt at the time.” Officers also found traces of Sweat’s DNA on a pepper shaker not far from where Matt was killed. The men may have been attempting to mask their scent with the spice to evade search dogs, a ruse used in the 1967 film “Cool Hand Luke.”

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

Over the weekend, police flooded the area, forming a 22-mile-radius circle that provided little opportunity for Sweat to escape — if indeed he was inside.

“They’re not standing next to each other, but they’re within line of sight. One has to be able to see the next one,” Franklin County Sheriff Kevin Mulverhill told local TV station WPTZ Sunday. “If Mr. Sweat is in fact contained in that area, there is no escape route. We’re going to get him.”

Police did, at around 3:20 Sunday afternoon. While Cuomo led a round of applause for officers who apprehended Sweat, upstate New Yorkers sighed with relief.

Cathy Leffler, a resident of Malone, cheered outside the medical center where Sweat was initially taken Sunday evening. She’d come to the hospital “to see it through,” she told the Associated Press.

“I feel like I can sleep tonight,” Leffler said. “Life can go back to normal. It’s over now.”

Leffler and her neighbors had been holding their breath for more than three weeks, ever since Matt and Sweat were reported missing early this month.

Both men were convicted killers — Matt serving 25 years to life for the murder and dismembering of his former boss, Sweat serving a life sentence without parole for the slaying of a sheriff’s deputy.

[Richard Matt, the dangerously charismatic escapee]

Officials say that Sweat and Matt broke out of their cells either on the night of June 5 or early June 6, using tools allegedly smuggled to them in frozen meat by Gene Palmer, a correctional officer at the prison. Court documents revealed that Palmer, who was arrested Wednesday, had previously given the men tools in exchange for elaborate paintings from Matt, who had a talent for both art and manipulation. Palmer also provided art supplies and gave the prisoners access to catwalks they would later use in their escape.

Sweat and Matt were in adjacent cells on the prison’s now-defunct honor block, where inmates were allowed to cook their own food on a hotplate on the catwalk. Instead of cooking the smuggled meat, they extracted the tools and used them over the course of several nights to cut through the backs of their cells, police said. The men then clambered onto the catwalks, which brought them into a “labyrinth of tunnels,” in Cuomo’s words, where they found a contractor’s job box. They cut away at the prison wall with power tools, sawing through layers of pipe, chains, steel and sewer.

Before fleeing the prison, they left a taunting yellow sticky-note on a pipe, according to news reports.

“Have a nice day!” it read, below a crude caricature of a smiling face.

Another prison worker, Joyce Mitchell, was said to have provided the smuggled tools — hacksaw blades, chisels, a punch and a screwdriver bit. (Mitchell, who was arrested on June 12 and is also charged with aiding the escape, does not believe that Palmer was aware that the meat contained contraband, according to USA Today.) Like Palmer, Mitchell was reported to have been won over by Matt, who she said made her feel “special,” according to CNN. Clinton County District Attorney Andrew Wylie also said that Mitchell and the men discussed killing her husband, a fellow prison employee, after their escape.

The 51-year-old supervisor in the prison’s tailor shop had also agreed to meet up with the escapees after their break-out and drive them to safety, according to authorities, but she backed out at the last minute.

Instead, the two men fled on foot, sheltering in the forests that cover much of the region and in cabins that were still empty so early in the summer. For weeks they eluded the hundreds of officers from an array of agencies who scoured the area attempting to track them down.

But tell-tale clues of their presence — a wrapper, a trace of DNA, a footprint, a whiff of their scent — gave them away, leading investigators closer and closer even as thousands of tips and reported sightings drew attention away from the area. Ultimately, the men never got more than 50 miles from the town they had fled.

But the terrain in this rural region along the border made tracking difficult, Cuomo said Sunday.

“This prison happens to be located in a heavily forested area, so this was an extraordinarily difficult row to hoe so to speak,” he said at the news conference.

Though the search for the missing men dragged on far longer than investigators — and residents of the region — would have wanted, the governor’s tone at the conference was congratulatory. He hailed Sgt. Cook as a hero, joking that the 21-year-veteran of the local New York State Police troop would get about 24 hours of credit from his teenage daughters before they started treating him like a “regular dad” again. And he credited an “unprecedented coming together of law enforcement” with finally ending the weeks-long manhunt.

“It is nice when it ends well,” he said. “… We wish it did not happen in the first place, but if you have to have it happen, this is the way you want it to end.”

More on the N.Y. prison escape:

PHOTOS: Second escaped murderer shot and in custody

N.Y. prison escapee Richard Matt killed by federal agents

N.Y. prison corrections officer arrested in connection with breakout

N.Y. prison worker arrested, charged with assisting killers’ escape

Richard Matt, the dangerous charismatic escapee at the center of N.Y. manhunt