The Lloyds TSB Foundation for Scotland was in line to receive £3.5 million from Lloyds Banking Group but the bank appealed against the payout at the Supreme Court.
The foundation, which supports thousands of Scottish charities, will now receive just £38,920 after judges ruled in favour of the bank in a decision that has been branded a defeat for the country's most vulnerable people.
Martin Sime, chief executive of the Scottish Council for Voluntary Organisations, said: "This is a sad day for charities in Scotland.
"The Supreme Court ruling in favour of the Lloyds Banking Group marks a victory for bankers and lawyers, while it is the vulnerable people across Scotland supported by the Lloyds foundation who will lose out at a time when need is rising in all of our communities.
"This news will taste bitter to many of the bank's Scottish customers."
The dispute between the foundation and the bank centred around a historic agreement said to entitle the charity to a share of the bank's profits.
In 2010, Lloyds decided to reinterpret the covenant so it they owed the smaller sum, prompting legal action from the foundation at the Court of Session in Edinburgh which went in favour of the bank.
The charity successfully overturned that decision at the Court of Appeal but Lloyds then launched the latest action at the Supreme Court – the UK's highest court – in which judges again found in favour of the bank.
Mary Craig, OBE, chief executive of the foundation, said: "After more than four years trying to resolve this situation, trustees are dismayed and bitterly disappointed by the decision by the Supreme Court, especially after the Scottish appeal court had ruled in our favour.
"There is no other appeal route open to us and, reluctantly, we must accept the decision.
"The trustees have acted on the basis of advice from eminent senior counsel in London and in Edinburgh.
"On various occasions, Lloyds Banking Group had the opportunity to bring matters to a close, particularly when the Inner House of the Court of Session vindicated the position of the Foundation.
"Instead, the banking group forced the appeal to the Supreme Court and the trustees had no alternative but to participate in that appeal process.
"In 2019, the formal covenant will end after the banking group invoked its right to terminate it in 2010.
"Trustees have been actively considering how best to secure long-term funds for the foundation, irrespective of the outcome of this court action.
"With the uncertainty caused now behind us, we will be able to turn our full attention to detailed planning for the future."
A spokeswoman for Lloyds Banking Group said: "We are pleased with today's decision from the Supreme Court.
"It is disappointing we could not reach an agreement with the Lloyds TSB Foundation for Scotland at the outset as we did with the group's other foundations.
"We are proud of our track record as one of the largest corporate funders of charities in the UK, including Scotland.
"Lloyds Banking Group has channelled more than £82m over the last 26 years to the Lloyds TSB Foundation for Scotland."
A new Bank of Scotland Foundation was set up to channel financial awards from Lloyds Banking Group in the wake of the dispute.
The spokeswoman said: "Our long-term commitment remains to be one of the largest contributors to Scotland's charities and communities."