A Tayside patient was held in a mental health unit for more than three years after they were declared ready for discharge.
The 1,196-day wait was the second longest in the country, falling just four days short of the record delay at NHS Lothian.
Opposition politicians said the “shock” figures were a stark demonstration of the SNP government’s failure to tackle delayed discharges.
The patient in Tayside was described as having complex needs and was waiting for a transfer to specialist facilities.
A BBC Scotland investigation found that nearly a third (29.4%) of acute mental health care beds in Tayside were taken up by those whose discharge dates had passed.
The health board said that figure, which was collated in February, fluctuates and was down to 16% at the beginning of August.
Bill Troup, head of mental health services for Tayside, said they are looking at how they can redesign inpatient and community services in their efforts to reduce delayed discharges.
“The reasons for delayed discharges within adult mental health services can be very unique and complex,” he added.
“For example, it may be necessary to work in partnership with third sector social care providers to specially commission a new building to accommodate a patient and any live-in carers.
“Legal implications linked to complex guardianship applications can also contribute to delays.”
Annie Wells, for the Scottish Conservatives, said: “The SNP has promised for years to tackle delayed discharge, but the figures show no sign of improvement.”
Scottish Labour’s Monica Lennon said the “shocking figures expose the serious problems we have with mental health provision in Scotland”.
“These figures should jolt the SNP government in Edinburgh into action and finally give mental health the parity of esteem with physical health that it needs.
Alex Cole-Hamilton, for the Scottish Liberal Democrats, said: “This is a national disgrace and a severe violation of human rights.
He said that only the Lib Dems have “set out a comprehensive and positive plan that will deliver a step change in mental health”.
Prof Jason Leitch, the Scottish Government’s national clinical director of healthcare quality and strategy, said the cases tend to be “enormously complex” and solutions for how they are treated take time.
“These are not the conventional delayed discharges where the system just needs to speak to each other a bit better and we’ll get people out in three or four weeks if we just work a little harder,” he added.
Health Secretary Shona Robison said when patients cannot leave hospital because of “extenuating circumstances” they are provided with “safe and appropriate hospital care until suitable care arrangements are put in place”.
“These cases are exceptional circumstances – mental health patients can present extremely complex needs where mainstream care provision is simply unsuitable.”