Outside groups spent millions helping third-party candidates siphon votes from Republicans, a move that eased the path to victory for some Democrats.