Hunslet-Barclay, the historic locomotive works in Kilmarnock that collapsed after a cashflow crisis, has been sold out of administration for £2.1m in a deal that saves 119 jobs.

Its sale marks the survival of a long-established Scottish engineering company that has refused to die, in spite of its track record of troubles dating back more than 150 years.

Administrator KPMG, which was appointed at the end of last month, said the company's business and assets had been sold to engineering group FKI on behalf of its railways subsidiary, Brush Traction.

The Ayrshire company, which made its name in the glory days of steam-driven locomotives, hit the buffers after becoming embroiled in a contract and production crisis, and around 20 jobs were axed in recent months.

A spokesman for KPMG said: "On October 26, 2007, the company was placed into administration after cashflow difficulties ultimately forced the directors to appoint Blair Nimmo and Tony Friar from KPMG Scotland as joint administrators."

Hunslet-Barclay's most recent problems are the latest in a long line of financial crises that have plagued it over the past century and a half - but it has always survived.

Hunslet-Barclay traces its history back to 1814 and former engineering works of Andrew Barclay, Sons & Co, which at the time was set up as a manufacturer of mill shafts, before branching out into the production of patented gas lamps.

In 1847, Barclay also set up workshops specialising in the manufacture of winding engines for the local coal mining industry, and in 1859 the company produced its first locomotive.

However, the money from the sale of Barclay's gas lamp patent was never paid, and a severe cashflow crisis pushed his company into sequestration the following year.

In 1871, Barclay set up another locomotive building business - known as Barclays & Co - for his younger brother and his four sons, which was closely aligned to his own company, but again all did not go well, and both firms were declared bankrupt within the decade.

However, in 1886, the business was relaunched as Andrew Barclay, Sons and Co, which chugged along until 1972, when it was acquired by the Hunslet group from West Yorkshire. It has since become part of the Waagner Biro group of Austria.

The company, which for many still resonates with the sounds of steam and diesel engines being crafted by skilled workers, was noted for constructing simple, robust locomotives, including the Drake, which was built in 1939 to ferry parts for munitions from factory to factory.

Nimmo said the firm, which now specialises in railway engineering projects and has carried out work for First Scotrail and Glasgow Underground, had endured a "tough time" over the past two years. "We are pleased to have completed a sale of the business and assets of Hunslet-Barclay, which secures the continuation of the business and skilled jobs in Scotland and represents a good result for the employees," he said.

"We would like to thank the customers, suppliers and above all the staff for their support through what has been a difficult period for all.

He added: "We believe today's deal will enable the business to continue to grow under the new owners and would like to wish them every success for the future."