The Nationwide is to buy the Dunfermline Building Society's branches, good loans and deposits, it has been confirmed.
The mutual was put up for sale after incurring losses of £26m.
The Nationwide said the 140-year-old brand would keep its name but that there may be redundancies from its back office and support operations.
The Treasury will take on about £1.5bn of commercial property lending and acquired mortgage debt under the deal.
The agreement with the Nationwide was struck less than 48 hours after the UK Government announced that the building society was to be put on the market.
The Bank of England used new powers under the Banking Act to rush through the deal and prevent the Dunfermline - Scotland's largest building society - from going bust.
The Nationwide has bought the Dunfermline's retail and wholesale deposits, branches, head office and most of its residential mortgage book.
The Treasury has placed the building society's £500m social housing portfolio into a bridge bank, owned by the Bank of England.
The remainder of the business - risky assets worth more than £900m - has been hived off and placed in the Building Society Special Administration Process, where they will be managed by administrators KPMG.
This includes £648m of commercial property loans - £500m of which had been made in the past three years - and £274m of buy-to-let and self-cert mortgages from defunct American finance house Lehman Brothers and GMAC.
The collapse in commercial property prices means that losses on these loans are likely to be significant.
Established in 1869, it is Scotland's largest building society
It employs about 530 staff
It has about 300,000 customers
Retail deposits total £2.35bn
Mainstream mortgage lending totals £1.02bn
The Treasury is due to reveal later how much was paid by Nationwide, and any taxpayer liability.
The Bank of England said: "It is business as usual for all customers. Dunfermline's deposit business will continue to operate normally.
"Savers can be assured that their money is safe.
"All of Dunfermline's staff have been transferred to Nationwide."
The new owner said Dunfermline's branch network, which has 245 employees, would remain intact but that it was likely that some staff would "no longer be required".
Scottish Secretary Jim Murphy said he had been given a guarantee that there will be no compulsory redundancies at any branch over the next three years.
Dunfermline Building Society customers give their reaction to the takeover
The BBC's business editor Robert Peston said there was bound to be significant job losses among the 289 people employed in Dunfermline's head office.
The Liberal Democrat MP and SNP MSP for Fife have both called for the Nationwide to provide clarity on how the sale would impact on jobs in the area.
Scottish Labour leader Iain Gray described the takeover as the "best option available" and Annabel Goldie, leader of the Scottish Conservatives, said she hoped it had secured jobs.
The deal comes after a weekend of claim and counter-claim about whether the building society had to be put on the market at all.
Chancellor Alistair Darling had said the Dunfermline would have needed between £60m and £100m to keep it going because of its exposure to risky assets.
But the Treasury said full nationalisation would not have provided "value for money".
Prime Minister Gordon Brown has defended the government's role, claiming that the Dunfermline's management had been the "author of its own mistakes".
However, the society's outgoing chairman, Jim Faulds, said government funding of £20m-£30m would have helped secure its future and dismissed claims the building society had debts linked to the toxic US sub-prime mortgage market.
Mr Faulds said he "warmly welcomed" Nationwide's involvement but was "deeply disappointed" that the government did not provide the support needed for the building society to continue as an independent operation.
"What we needed was not capital but access to the liquidity scheme and the Financial Services Authority raised the bar for access to the liquidity scheme," he said.
"We were not asking for money to be given to us. We were asking for a loan, which would have been repaid with interest.
"We could have serviced a loan of between £20-£30m. That's what we think we needed. It would have been secured against a good property book and a social housing book that's rock solid."
The Scottish Government had offered money to help keep the Dunfermline going, but did not get Treasury approval for the move.
First Minister Alex Salmond welcomed the Nationwide deal but said there were "perplexing" questions over how the society had been treated by the Treasury and the Financial Services Authority.
Graham Beale, chief executive of Nationwide, said it was in a "unique position" to be able to provide support to Dunfermline.
"We regard it as both responsible and commercially beneficial to undertake this transaction," he said.
Dunfermline's board - including chief executive Jim Willens, who is a former board director of Nationwide - will resign after the deal.
The building society, which has 34 branches, was founded in the Fife town from which it takes its name in 1869.
A protest about the sale took place at the mutual's head office in Dunfermline on Monday morning.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.