The 17th-century portrait of an austere-looking Spanish writer had hung in Penrhyn Castle for nearly 150 years, unvisited by art experts and assumed by the National Trust, which owns the castle, to be of no great value.

That was until a recent visit by Benito Navarrete Prieto, a distinguished art scholar who made the journey from Seville to north Wales on a hunch that a painting assumed to be a copy might just be the real thing. Now Prieto has established that the artwork was indeed a lost masterpiece by Bartolomé Esteban Murillo, one of Spain’s great painters.

Last week, the art world marvelled as Leonardo da Vinci’s 500-year-old depiction of Christ sold at auction for a record £341m. The restored Salvator Mundi had long been considered a copy but was reclassified as authentic. The discovery of a Murillo in Penrhyn Castle, near Bangor in north Wales, is not quite on the same scale. But it is a major event for European art: there are barely a dozen known portraits by the artist and those few that do exist are worth millions.

“It is an absolute masterpiece,” Prieto said. “Magnetic.”

Transported from Penrhyn, the portrait is the centrepiece of a major exhibition on the artist at the Frick Collection in New York, before transferring to the National Gallery in London in February.

One of the US exhibition’s curators, Xavier F Salomon, said the discovery was hugely exciting, and that he regretted relying on previous judgments by other art historians. “Most scholars have written that there are two versions [of the portrait], both copies after a lost original. One copy was in Seville, which I’ve seen and is clearly a copy,” he said.

Facebook Twitter Pinterest The rediscovered Murillo painting in full. Photograph: Courtesy of Sotheby’s

Painted around 1751, the copy is thought to have been commissioned by the sitter’s family when the original Murillo was sold. Now attributed to the 18th-century Sevillian painter Domingo Martínez, it hangs in Seville town hall.

When it came to the Welsh example, Salomon said the literature featured “terrible old black and white photos”. He requested a colour image for his exhibition catalogue and featured it as a “copy”, even though he recalled his first impression was that “this looks really good”.

“I thought ‘people have always said it’s a copy, it’s got to be a copy’. Which is, of course, a mistake art historians should never make. Go with your gut feeling and you should follow up. I didn’t.

“Benito went to Wales and realised how great the painting was and that everyone had been wrong in calling it a copy. The mistake – myself included – is just that no one bothered to go there, and everyone kept repeating that it was a copy. It was hidden in plain sight. It’s not coming out of a location that’s unknown. The house was open to the public.”

The painting was among old masters collected in the mid- to late-19th century by Baron Penrhyn for his neo-gothic pile. Today, the castle’s collection includes paintings, furniture and books. The Murillo was attributed to the artist when it was acquired in the 1870s, but by 1901 it had been downgraded.

Describing it as exceptional, Salomon said: “It’s difficult to add a painting to an exhibition that’s already opened but I literally found out about this painting on the Friday and the exhibition was opening on the Monday. There was an insane weekend – I started calling everyone in Wales and Spain to find out more. I hadn’t seen it and I wanted to be sure it was absolutely right … The picture arrived here and we hung it. It’s absolutely fantastic.”

Murillo worked primarily in Seville until his death in 1682, aged 64. Among his masterpieces are paintings for the city’s convent of San Francisco and for the church of the Caridad, including Christ Healing the Paralytic at the Pool of Bethesda, now in the National Gallery. Such was Murillo’s prestige that, at one point, the king of Spain refused to allow them to be exported. In July, Sotheby’s in London sold his Ecce Homo – a painting of Christ wearing the crown of thorns – for £2.75m.

James Macdonald, the senior director of old master paintings at the auction house, said he had sold works by the artist privately for substantially more. He described the rediscovered painting as striking and added: “The emergence of this fine portrait of one of the most important cultural figures in Seville represents an important addition to the artist’s oeuvre.”

Murillo is admired for his ability to bring out the character of his sitters. The rediscovered portrait depicts Don Diego Ortiz de Zúñiga, who wrote a history of Seville. Dressed in black with the insignia of the Order of Santiago, he is set within a stone cartouche supported by two cherubs. The oil on canvas measures 113cm by 94cm. Its qualities were concealed beneath a layer of discoloured varnish that has been removed.

The exhibition at the Frick runs until 4 February 2018 and will then transfer to the National Gallery in London.