The elderly man had been anaesthetised and the surgeon was cutting into his limb when the knife struck a metal plate that was unexpectedly found in the leg.
The amputation was halted when surgeons and operating theatre staff realised they did not have suitable equipment and they discussed how they should proceed.
It was decided to send a worker to a nearby branch of B&Q to see whether a suitable instrument or tool could be found that could cut through the plate.
However, the hardware store was closed, as the operation at Ayr Hospital was being carried out in the evening.
Medics searched for an alternative instrument and discovered a “rusty hacksaw” from old hospital stock lying in a store.
As a last resort, it was disinfected and the operation went ahead but staff who were present later raised concerns with management.
It is understood the patient and his relatives were told about what happened some time after the incident.
A health board source said: “An elderly man who was a patient at Crosshouse Hospital needed a leg amputation and was taken to Ayr Hospital for the operation, because that’s where the vascular surgeons are based.
“The operating theatre was prepared, he was anaesthetised and the operation began but it was halted after the surgeon had difficulty cutting further.
“That’s when he discovered he’d hit a metal plate that they didn’t know about.
“So he frantically sought advice from the consultant orthopaedic surgeon, who suggested going to B&Q.”
However, the store was closed because the operation was being carried out after 9pm and a surgeon decided to use the saw found in a storage area.
The source added: “The saw was sterilised by soaking in some disinfectant solution and the surgeon proceeded to complete the amputation after cutting through the metal plate.
“If this is a proper investigation, then it should be shared with all.
“This should never have happened in the first place. I have never come across anything similar in my career.”
Scottish Conservative health spokesman Jackson Carlaw said: “This is simply incredible – an indescribable way to treat any patient.
“Despite the UK’s advances in modern medicine, this episode has all the finesse of improvised surgery on Nelson’s flagship during the Battle of Trafalgar.
“I would hope that NHS Ayrshire and Arran thoroughly investigates this as a matter of urgency.”
Ann Gow, interim nurse director, said in a statement: “NHS Ayrshire and Arran is currently conducting a significant adverse event review into a recent incident within University Hospital Ayr, where standard procedures were not followed.
“The findings of this review and any subsequent recommendations will be shared with clinicians, as well as the family of the patient.”