The 54-year-old man tried to resist arrest when cornered by police on Wednesday night in Vieira do Minho, but did not use the pistol he was carrying.
The former shepherd, who had a deep tan and a long beard, was serving a 10-year jail sentence when he escaped in 1993.
His family and friends had provided him with food and medicine, police said.
Cave in which the fugitive is believed to have lived
The former shepherd lived in caves in hills near his family’s village
“Since his escape, he hid out and lived in three or four caves in the region, which he knew well,”
Chief Inspetor Carlos Gomes of the judicial police in Braga told AFP news agency.
“He fed himself on fruits and had never seen a doctor, but he seemed to us to be in good health,” he added.
Mr Gomes said officers had carried out surveillance on the caves over the past two years after receiving reliable information that the man was hiding in the hills around his home.
The fugitive “looked like Robinson Crusoe” and had been keen to talk to police after being recaptured, he added.