Richard W. Matt, one of the two convicted murderers who engineered an elaborate escape from New York’s largest prison, was shot and killed on Friday by a federal agent, the authorities said, ending one prong of a three-week manhunt that spread over large stretches of the state’s northern terrain.

A team of agents from the federal Customs and Border Protection agency found Mr. Matt in the woods in Malone, N.Y., after he fired a shot at the back of a camping trailer, Gov. Andrew M. Cuomo said at a news conference. Officers heard him cough as he fled on foot, and a federal agent killed him when Mr. Matt, still armed with a 20-gauge shotgun, refused orders to put up his hands, the authorities said.

On Friday night, officers closed in on the other inmate, David Sweat, 35, who was believed to be penned inside a perimeter of law enforcement officers, Superintendent Joseph A. D’Amico of the New York State Police said at the news conference.

The officers had not seen Mr. Sweat, but they believed that he had been near Mr. Matt when Mr. Matt shot at the camping trailer, officials said.