Rep. Mark Sanford, one of President Trump’s sharpest Republican critics in Congress, was ousted by a primary challenger on Tuesday after Trump waged an extraordinary last-minute effort to defeat him.

The South Carolina representative lost to state legislator Katie Arrington, who won Trump’s support just hours before the polls closed on Tuesday. Trump lashed out against Sanford, declaring him “nothing but trouble” in a tweet and referencing his 2009 extramarital affair.

Sanford becomes just the second House Republican to lose in a primary this year. The president’s broadside marked the first time he targeted a congressional Republican incumbent in the midterms.

In Sanford, Trump chose a well-known former governor, who, among other criticisms, held him partly responsible for a shooting at a congressional baseball practice by stoking national tensions.

“Based on the numbers I see, I think I’ll end up losing this election,” a resigned Sanford told supporters Tuesday night. With nearly all the vote tallied, Arrington had slightly more than half the vote — enough to clinch the nomination and avoid a runoff.

“We are the party of President Donald J. Trump,” Arrington said to her backers.

Virginia primary election results 2018: Senate and House races

Upon returning to Washington early Wednesday from his summit in Singapore, Trump congratulated Arrington in another tweet and said that his advisers had cautioned him against getting involved in the race.

But “with a few hours left I felt that Katie was such a good candidate, and Sanford was so bad, I had to give it a shot,” Trump wrote.

The intraparty strains came on a day when other cracks emerged in the GOP establishment, all of them reflecting Trump’s dominance. On Capitol Hill, Sen. Bob Corker (R-Tenn.) mocked his colleagues for being afraid to “poke the bear” and cross the president by voting on an amendment to grant Congress more authority over tariffs. And moderate House Republicans fell short of securing enough support to force votes on sweeping protections for young undocumented immigrants — a measure at odds with Trump’s hard-line immigration posture.

Rep. Justin Amash (R-Mich.), who clashes frequently with party leaders, responded to Trump’s tweet with one of his own defending Sanford.

“Unlike you, Mark has shown humility in his role and a desire to be a better man than he was the day before,” he wrote.

Elsewhere, voters made their picks for key November elections for Senate, House and governor in Virginia, Maine, Nevada and North Dakota, on a day with considerably less drama and lower stakes than primaries in recent weeks.

In North Dakota, Rep. Kevin Cramer won the Republican nomination for Senate and will face Democratic incumbent Heidi Heitkamp, who had no primary challenger. The race is a top pickup opportunity for Republicans, who are trying to hold onto a narrow 51-to-49 Senate advantage.

Trump personally recruited Cramer to run, but there has been tension between the congressman and the White House. Trump has treated Heitkamp better than other red- state Democratic senators, as she has passed party lines to vote for some of his policies and nominees.

State legislator Kelly Armstrong won the GOP nomination for Cramer’s House seat and will be favored in November.

In Nevada, the Senate race has emerged as a marquee midterm showdown. Dean Heller is considered the most vulnerable Republican senator running for reelection. He won thanks to some help from Trump: The president shooed his biggest challenger, activist Danny Tarkanian, out of the race.

On the Democratic side, one-term Rep. Jacky Rosen defeated five long-shot candidates.

Tarkanian, who lost the 3rd Congressional District to Rosen in 2016, plunged back into that race and raised four times as much money as his closest challenger, winning handily.

The Democratic winner was Susie Lee, a philanthropist who previously lost a primary in the nearby 4th Congressional District and had locked up most party support.

The Democratic-leaning 4th District, meanwhile, was set for a rematch between the players in one of 2014’s biggest upsets. That year, voters there ousted Democrat Steven Horsford after one term and elected Republican Cresent Hardy, who was unseated in 2016 by a Democrat who in December announced a scandal-driven retirement. Horsford and Hardy both won their primaries.

Both parties also decided competitive, pricey primaries for governor. Attorney General Adam Laxalt defeated a fellow beneficiary of the 2014 Republican wave, state Treasurer Dan Schwartz, for their party’s nomination. Democrats chose Steve Sisolak, a Clark County commissioner.

In Maine, voters for the first time picked party nominees in a “ranked choice” system that let them assign preferences to several candidates. If no candidate wins an outright majority, ballot-counters eliminate the candidate with the fewest first-choice votes and redistribute that person’s support to the runners-up — and so on, until one candidate comes out on top.

Businessman Shawn Moody won the Republicans’ four-way race for governor. The Democrats were sorting out a seven-way contest, with every candidate promising to end Republican Gov. Paul LePage’s blockade of Medicaid expansion.

The Democratic primary in Maine’s 2nd Congressional District has drawn national attention for becoming a faceoff between two kinds of candidates that the party has been trying to recruit in swing seats: Jared Golden, an Iraq War veteran and state representative, and Lucas St. Clair, the wealthy heir of the Burt’s Bees fortune.

Golden was leading late Tuesday. The eventual winner will challenge Republican Rep. Bruce Poliquin.

In South Carolina, Gov. Henry McMaster was forced into a runoff against business executive John Warren. McMaster was one of the few established Republicans in the state to back Trump in 2016, and became governor when Trump named Nikki Haley as United Nations ambassador.

State Rep. James Smith, who is backed by former vice president Joe Biden, won the Democratic nod for governor.

In the 4th Congressional District, where Republican Rep. Trey Gowdy is leaving one of the country’s most reliably GOP seats, 12 Republicans were seeking to replace him. Former state lawmaker Lee Bright advanced to a runoff. The second spot was yet to be decided.

There was less drama than scandal in the 5th congressional District, which Democrats nearly won in a 2017 special election — before it was revealed that Archie Parnell, the party’s surprisingly adroit candidate, had once assaulted an ex-wife. Democrats urged him to quit, but Parnell released a statement asking for forgiveness, remained on the ballot — and won.