Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

Convicted murderer and escaped inmate David Sweat was shot near the Canadian border Sunday by a New York State Police officer, according to authorities. He was listed in critical condition Sunday night.

"The nightmare is finally over," New York Gov. Andrew Cuomo said at a news conference late Sunday. "It took 22 days, but ... let's give a big applause to the men and women of law enforcement who did a great job."

Sweat was wounded but is alive and was taken into custody, state police said. He was spotted by Sgt. Jay Cook about 3:20 p.m. ET in the town of Constable, less than six miles from the Canadian border, police said in a statement.

Cook thought Sweat looked suspicious and told him to "freeze," and when Sweat didn't, Cook shot him twice in the torso before he could run to the tree line, officials said. Sweat was then handcuffed, taken into custody and placed on a gurney, the sources said.

Sweat was transported to Albany Medical Center. In a news conference Sunday night, the center's director, Dennis McKenna, declined to discuss details of Sweat's condition, saying only that he was being treated by trauma surgeons and kept in a secure, locked unit.

New York State Police troopers Xaymara Morales and Jon Giddings and Sgt. Jay Cook. New York State Police

Joy Patterson, who lives on Coveytown Road in Constable, told NBC News that she saw a flurry of police activity near her home. She learned that the authorities had cornered Sweat on her neighbor's property.

"We're just happy that he's been caught," she said. "We didn't think they'd get up this far, but he did."

Sen. Chuck Schumer, D-New York, told The Associated Press that no officers were hurt.

Cuomo said that, in addition to grilling Sweat on how the escape plan took shape, officials will be conducting an investigation into the prison.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

"It was the first escape in 100 years, but one escape is one escape too many," the governor said. "Anyone who we find who was culpable and guilty of cooperating in this escape will be fully prosecuted."

He added: "Today ends with good news. These were really dangerous, dangerous men, both Matt and Sweat. These were killers. ... We could not tolerate them being on the loose."

Related: Escaped Inmate Richard Matt Died From Three Shots to Head: Autopsy

The news of Sweat's capture comes more than three weeks after he broke free from Clinton Correctional Facility and two days after Richard Matt, 49, the man he escaped with, was killed by law enforcement.

Matt was shot dead in Malone, about 40 miles away from the prison and about six miles south from where Sweat was shot. State police said Friday that investigators believed the inmates were trying to cross the Canadian border.

At the news conference with Cuomo, New York State Police Superintendent Joseph D'Amico said the same.

"Where Sweat was, I can only assume he was going for the border — he was that close," D'Amico said. "And we couldn't be more happy that we apprehended him. It's been a long three weeks."

Related: Richard Matt's Former Accomplice Lee Bates: 'Nightmare' Is Finally Over

D'Amico said the inmates may have used pepper to disguise their scent from police dogs.

Investigators were able to obtain DNA off a pepper shaker at one scene and believed that "possibly these two males were using pepper to throw the scents off of the dogs who were tracking them."

"We did have difficulty tracking, so it was fairly effective in that respect," D'Amico said.

The exhaustive search began when Matt and Sweat broke out from the maximum-security section of the Dannemora prison on June 6 in a sophisticated and brazen plan in which they cut holes in the backs of their cells with power tools.

Two prison workers have been arrested in connection with the escape.

Joyce Mitchell, who worked as an instructor in the prison's tailor shop, was arrested June 12 and charged with a felony count of promoting prison contraband and a misdemeanor count of criminal facilitation. She was planning to be a getaway driver for the inmates after the early-morning breakout but got cold feet, officials have said.

A prison guard, Gene Palmer, was later arrested and charged with promoting prison contraband, two counts of tampering with physical evidence and one count of official misconduct. Palmer told police that he allowed the prisoners outside their cells and gave them supplies but never thought they would escape.

David Sweat after his capture Sunday.

Sweat was serving a life sentence for killing sheriff's Deputy Kevin J. Tarsia on July 4, 2002. Tarsia's sister-in-law, Lisa Tarsia, posted on Facebook after Sweat's capture that her brother-in-law "can once again Rest in Peace."

"Feeling so thankful for all the members of Law Enforcement that have spent the last 3 weeks away from their families to track down these animals," she wrote.

Matt was serving 25 years to life for brutally killing and dismembering his former boss.

Both were added to the U.S. Marshals Service's 15 Most Wanted Fugitives list during their time on the lam, and $25,000 each was offered as reward money on top the $50,000 offered by New York for information leading to either inmate.

Cuomo said Friday that the weeks-long search had been "expensive," although he couldn't give a number. Whatever the cost, Cuomo said, there was "no doubt, in my opinion, that it's worth it."