Record turnout and a backlash against Trump and Elon Musk, who had largely hijacked the campaign, played a role.