It involved backroom deals, alliances, and last-minute overtures to sway key states.