It is not often Gordon Brown goes to bed at 10 o'clock, but such was his eerie calm over the rescue package that he clocked off comparatively early on Tuesday, rising at 5am to phone Nicolas Sarkozy, the French president, who has been his closest European ally during this crisis.

By the time he turned the lights out at No 10, the PM already knew that the banks had abandoned their opposition to recapitalisation.

In the Treasury war room overlooking St James's Park, central London, his chancellor, Alistair Darling, was thrashing out the details of the bail-out with ministers, lawyers and executives from the eight leading banks, who had no real option but to strike a deal despite anxiety about the stigma it might attach to their businesses.

Anticipating the long and tense night ahead for him and his team, Darling had taken matters in hand at 8.30pm, personally ringing one of his favourite restaurants, Gandhi's in Kennington, south London, to order £245 worth of rice, karahi lamb, tandoori chicken, vegetable curry and aloo gobi.

With Darling were three ministers - Paul Myners, the new City spokesman and former hedge-fund boss, Shriti Vadera, minister for economic competitiveness and small business, and Yvette Cooper, the chief secretary in the Treasury.

Myners, a close ally of Brown, only joined the government on Friday, but he was familiar with the recapitalisation plan before his appointment, and played a crucial role ahead of Tuesday evening's summit, meeting all the banks to win assurances they would support the scheme.

Others on the government side included Tom Scholar, a Treasury official who had had only two hours sleep since Sunday, and Nicholas Macpherson, the Treasury permanent secretary.

The bank bosses made an unlikely group. Among them were Sir Fred Goodwin, the Glaswegian raised in a Paisley housing estate who runs Royal Bank of Scotland; Barclays boss John Varley, an archetypal City gent, with a taste for old-fashioned suits, high-waisted trousers and braces; Eric Daniels, the understated, tanned American who is chief executive of Lloyds TSB; and HBOS chief Andy Hornby, a former management consultant who, at 41, is one of the youngest bosses of Britain's leading companies. Sir Mervyn Davies was also present, in two roles: as chairman of Standard Chartered, and as a long-standing government adviser.

HSBC, which has indicated it does not intend to turn to the government for any help, sent a relatively junior executive, raising the hackles of some of the other banking bosses. The HSBC chief executive, Mike Geoghegan, was not even in the country. The atmosphere at the meeting was tense, with the need to deliver a solution to the crisis abundantly clear to everyone present.

In the talks, acute sensitivity was shown by the banks to the conditions that ministers wanted to attach to recapitalisation, with much haggling over the terms of access to the loan guarantee. Though he was not there personally, the prime minister was determined that, in return for such a massive taxpayer investment, it had to be seen the banks were not getting off scot free. Strings had to be attached.

In return for taking a stake, the government argued it needed to be satisfied about each bank's policy on executive remuneration, dividend payments, supervision arrangements and a commitment to lend to homeowners and small businesses.

Darling had studied the political backlash that greeted US Treasury package, leaving the Republicans badly exposed. Other conditions demanded of the banks were over access to the extension of the existing special liquidity scheme that provided a £250bn loan guarantee - or insurance - to encourage banks to lend to each other. This would be offered in return for a commercial fee to the government.

Darling, though, had to reassure the banks that they were not being taken over, and that the scheme was voluntary.

The bones of the deal were probably in place before Darling went to bed at No 11 just before 1.40am. He got up to return to the Treasury at 4.50am to sanction the final stages of the deal. Some of the banking chiefs had already drifted home.

The prime minister was up for the final "signing ceremony" before dawn.

Eventually there was a conference call when those who had left were briefed on how an era in British banking was being brought to a close.

The agreement had been completed only two hours before a detailed statement was due to be disclosed to the markets. John Kingman, another senior treasury official, was tasked with implementing the plan, and Scholar given the job of trying to persuade other EU countries to adopt the British proposals.

Brown, it seems, had not just been involved in shaping the deal. Behind the scenes, he has also been trying to encourage an international response, including the idea of a meeting of G7 leaders in the next fortnight.

· This article was amended on Monday October 13 2008. The Treasury building overlooks St James's Park, not Green Park; both are in central, not west London as we said in the article above. This has been corrected.