WASHINGTON — Republicans nervously eyeing the White House race are learning a lesson with Donald Trump that Senate Majority Leader Mitch McConnell painfully learned in 2010 and 2012.

Faulty outsider candidates blew several perfectly winnable Senate elections those years. Since then, the crafty Kentuckian has tried to make all the right moves. McConnell, the top fundraiser and field general for the Senate Republicans, helped orchestrate the 2014 midterm romp that delivered the Senate back to his party. McConnell and national Republicans aggressively swung behind incumbents and favored candidates while crushing the chances of tea partyers and far-right hopefuls unlikely to prevail in the general election.

McConnell-backed candidates swept this year’s primary cycle. He helped convince Sen. Marco Rubio to run for re-election after the Floridian’s failed presidential bid, boosting the GOP chances of holding the seat. Just two weeks ago, the GOP was cautiously optimistic that the party would retain control of the Senate despite defending 24 of the 34 seats up for grabs this year.

It all may prove futile.

Trump was already sinking in opinion polls after his poor performance in his first debate with Democrat Hillary Clinton last month. His crude, predatory comments about women in a 2005 videotape that leaked on Friday threatened to scuttle his campaign altogether and take the GOP’s Senate majority with it.

McConnell is a disciplined politician, and when it comes to Trump, the senator has kept as quiet as possible after a brief statement in May signaling his support for the presidential nominee. On Monday, as House Speaker Paul Ryan, R-Wis., stoked controversy by vowing never to campaign for Trump, McConnell simply kept his own counsel.

“If some of you are here thinking I’m going to elaborate on the presidential election, let me disabuse you of that notion,” McConnell said in an address to the Danville, Kentucky, Chamber of Commerce. “If you are interested in the presidential election you might as well go ahead and leave because I don’t have any observations to make about it.”

For Republicans, Trump is reminiscent of Senate candidates like Richard Mourdock of Indiana and Todd Akin of Missouri, who defeated establishment favorites in GOP primaries in 2012 only to make politically stupid remarks about rape and lose by wide margins in states swept by GOP presidential nominee Mitt Romney. In 2010, bad tea party candidates lost in Nevada, Delaware and Colorado, enabling Democrats to hold those seats in spite of that year’s Republican wave.

“The biggest lesson that the Senate side had learned that perhaps the rest of the party has lagged on is that in order to win general elections you need to win primary elections with candidates who have a broad mainstream appeal,” said GOP consultant Josh Holmes, a McConnell confidante and former campaign manager. “What manifested itself in Senate elections in ’10 and ’12, that was subsequently corrected in ’14 and ’16 and has for the first time hit the national stage.”

McConnell, however, has more sway over his domain on Capitol Hill than Republican National Committee Chairman Reince Priebus, whose laissez-faire approach to the presidential field helped produce Trump.

For instance, McConnell himself led the charge against conservative groups like the Senate Conservatives Fund, and he beat back a tea-party challenger in his own re-election campaign two years ago. This year, tea party challenges to Sen. Richard Shelby, R-Ala., John McCain, R-Ariz., and Lisa Murkowski, R-Ala., all fizzled. McConnell also swung behind the decisive primary win of Rep. Todd Young, a more viable general election candidate, over Rep. Marlin Stutzman for an open GOP-held seat in Indiana.

“Having aggressively beaten some of the professional conservative groups last cycle was really important in terms of drying up their money and ability to cause mischief,” said GOP consultant Brian Walsh of Rokk Solutions. “They just didn’t have the resources to seriously make trouble for incumbents this cycle.”

McConnell, allies say, is aggressive in urging incumbents to not get caught napping — either when facing a tea party primary challenger or an unexpectedly tough fall campaign. Not a single GOP seat fell to Democrats two years ago.

Senate races, however, have increasingly moved in synch with national trends, and Democratic Senate candidates have done particularly well in presidential years. So regardless of how strong a campaign McConnell allies like Sen. Pat Toomey of Pennsylvania are running, if Trump loses a state by 10 points instead of, say, five points, there’s very little they can do to save themselves. That’s why Trump’s sinking poll numbers have Republicans so alarmed.

Advisers say McConnell almost certainly won’t withdraw his endorsement of Trump. To do so could put endangered candidates, especially in states where the billionaire nominee has an avid following — like North Carolina, Missouri, and Indiana — in a difficult spot.