Douglas Steedman, from Bothwell, presented the weapon to staff at Low Parks Museum in Hamilton.
He said: "This pistol has been in my family for generations. Family tradition has it that it belonged to a Covenanting ancestor, David Hackston of Rathillet, which is near Cupar.
"The pistol features an engraved letter 'R' on the stock and my family believe this stood for Rathillet.
"I am delighted to make the donation to the South Lanarkshire museum's collection and that the pistol has found a good home where it will be preserved for future generations."
Hackston commanded forces of Covenanters at the Battle of Drumclog on June 1, 1679 and again at the Battle of Bothwell Bridge on June 22 that year.
He was later captured and executed in Edinburgh on July 30, 1680.
Assistant museums officer Barrie Duncan and museum intern Michael Allan worked with senior curators at Glasgow Museums and the Royal Armouries in Leeds to establish the background of the pistol and discovered it was of Spanish origin.
But Mr Duncan said: "Establishing when the pistol was made proved a bit more difficult.
"The earliest expert suggestion for date of manufacture was from the late 1600s and while it has not been possible to confirm the link to the Covenanters, the pistol is a rare example of its kind with a long connection to this area."
Gerry Campbell, general manager of South Lanarkshire leisure and culture, officially accepted the gun into the council's collection.
He said: "We are delighted and very grateful Mr Steedman chose to donate this rare 17th century Spanish pistol to our museum's collection in South Lanarkshire.
"I am sure its history and intrigue will be of interest to many."