How the $2 trillion deal came together — and nearly fell apart