David Sweat, one of two New York state inmates who escaped from prison three weeks ago, was shot and taken into custody by U.S. law enforcement officials on Sunday.

Sweat was caught in the town of Constable, New York, two days after a federal agent shot and killed Richard Matt, the other escapee from a maximum security prison in New York.

A massive, wide-ranging manhunt for Sweat ended more than three weeks after it began, with the escaped murderer in custody. "The nightmare is finally over," New York Governor Andrew Cuomo told reporters at a Sunday night news conference.

Cuomo said a state police sergeant recognized Sweat as he walked along a road about two kilometers from the Canadian border. As the sergeant tried to stop him, Sweat fled. The officer opened fire, striking him twice in the torso. Sweat was not armed at the time.

FILE - New York State Police photos show inmates David Sweat, left, and Richard Matt, who escaped from the Clinton Correctional Facility in Dannemora, N.Y., June 6, 2015.

The escapee was arrested and taken to a hospital in stable condition, Cuomo said.

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

They were added to the U.S. Marshals Service's 15 Most Wanted fugitives list two weeks after breaking out of prison.

The two escaped with the help of tools hidden in packages of frozen hamburger meat that they received. Once out of their cells, they traveled through a maze of internal passages and catwalks built for prison maintenance work and eventually emerged from a sewer outside the maximum security compound.

Two prison employees have been arrested for helping Matt and Sweat escape. Gene Palmer and Joyce Mitchell are accused of helping to smuggle in the tools, including hacksaw blades and bits for power drills.