Some patients have waited more than a year to be discharged from hospital even though they were clinically ready to leave, new figures from the Scottish Liberal Democrats have revealed.
Freedom of information requests by the party uncovered the longest periods patients across the country had their discharge from hospital delayed for health and social care reasons between 2013 and 2016.
The longest wait was by a patient in Dumfries and Galloway, who was kept in hospital for 508 days in 2013/14.
Delayed discharges of more than a year were also recorded in Fife and Highland health boards, while waits of more than six months were found in Ayrshire and Arran, Grampian, Greater Glasgow and Clyde, Lanarkshire, Shetland and the Western Isles.
The number of patients waiting for more than three months represents a small minority of those who experienced a delayed discharge during the three-year period.
Several boards, including Forth Valley, Lothian, Orkney and Tayside, were not able to provide the data.
Delays for health and social care reasons include patients waiting on a care home place, social care support to enable them to live in their own home, and those waiting on a needs assessment to be conducted.
Lib Dem health spokesman Alex Cole-Hamilton said: "In November I asked the First Minister about a constituent of mine who had spent 150 nights in hospital due to delayed discharge. Nicola Sturgeon described the situation as unacceptable.
"What then are we to make of patients in hospital for up to 500 nights, perhaps because carers can't be found to visit them at home or there isn't a care home place available?"
In September 2013, there were an average of 22,979 beds available compared to 21,815 in September 2016.
Mr Cole-Hamilton added: "Under the SNP, 1,000 beds were lost from Scotland's hospitals during the same three years. Our under-pressure NHS can ill afford delayed discharges on this extreme scale."
A Scottish Government spokesman said: "The latest official figures show a 5.1% reduction in bed days associated with delayed discharge in 2016 compared with 2015 - while the same period in England experienced a 23% increase.
"One unnecessary delay, however, is one too many and we have repeated our ambition and expectation that our new integrated health and social care partnerships will address this.
"The draft Budget announced an additional £107 million to transfer from the NHS to health and social care partnerships to support sustainability in the care sector, bringing the NHS contribution to enhancing social care to around £500 million next year, and that funding will be used to further improve social care provisions."