MODESTO, CALIF. — When county officials from California flew across the country last month to hear President Trump speak at the White House, they got an earful from the commander in chief.

Trump slammed the Golden State, which has suffered through more than five years of severe drought that ended only last year, for sending its water out to sea rather than using it to nourish crops. He dismissed that the notion the state had endured a historic dry spell and threatened to withhold federal funding.

“California, get on the ball,” Trump concluded. “Because we’re not going to hand you any more money.”

For many, Trump’s commentary was just another off-the-cuff mischaracterization. Of course, scientists say, California suffered through a drought — one of its worst ever on record.

Trump’s speech was just small part of a deluge of activity from the president and his deputies in recent months aimed at eventually delivering more water to farms in California’s Central Valley — and, in the near term, buoying the prospects of Republicans here running for reelection in Tuesday’s midterms.

For decades, farmers in the Central Valley have found themselves knotted in a tug-of-war with coastal residents over how much of California’s finite water supply should be divided among sating city dwellers, supplying habitat for river critters and cultivating crops. The drought emergency, which Gov. Jerry Brown (D) only official declared over in 2017, made those tensions worse.

With California’s state government firmly controlled by urban Democrats, California’s almond, walnut, dairy and grape producers have increasingly turned to the federal government for help after Republicans took the White House in 2017.

As if on cue, Trump waded into the debate last month during his speech by singling out an endangered fish — the three-inch delta smelt — for ridicule because California wanted to divert water from the Central Valley to protect it.

“It’s doing very poorly,” Trump said last month. “Nobody knows what a smelt is. I still don’t know what a smelt is.”

With Republicans holding about a half-dozen vulnerable seats in California, according to the Cook Political Report, Democrats believe their path to recapturing the House runs, like San Joaquin and Sacramento rivers that have made the Central Valley into an agricultural powerhouse, right through the Golden State.

No Republican incumbent here in California’s fruit-and-nut basket is more vulnerable to the gush of Democratic enthusiasm than Jeff Denham.

The four-term farmer-turned-congressman is running in a district Hillary Clinton won by three points in 2016. Denham’s opponent, a “Medicare-for-all” Democrat named Josh Harder, is trying to tie the incumbent to Trump on issues like health care and immigration.

That Democratic message may be finding an audience here in this sunny corner of the San Joaquin Valley. A New York Times-Siena College survey in late October showed that 47 percent of residents support Harder while 45 percent back Denham. The poll’s sample size of 501 likely voters carries a margin of error of nearly 5 points, suggesting either candidate can win on Tuesday.

No resource is more vital to livelihoods in California’s 10th district than water. On that issue, Harder is hard to distinguish from his opponent.

Both Denham and Harder oppose a state plan to flush more water down Central Valley rivers to help sustain endangered river fish. Both also oppose another proposal to construct two massive tunnels under the Sacramento-San Joaquin Delta to deliver water to points south, including Los Angeles.

“Water is a bipartisan issue,” Harder told The Washington Post in an interview. For a century, he said, Republicans and Democrats here have worked “together to make sure that the valley has enough water.”

In a debate in September, Denham conceded as much: “There’s not a more critical question than the future of our water here. And Josh is right, this is not a partisan issue for us here in the Valley.” (The Denham campaign declined to make the congressman available for an interview.)

But ahead of the election it has been California’s Republican delegation in Congress that has marshaled the power of the federal government to try to bring more water to the Central Valley.

In October, 18 days before Election Day, Trump pledged to “eliminate all unnecessary burdens” on water supply in California and other Western states. The president signed a memorandum telling federal agencies to find regulations to cut and to swiftly approve environmental reviews for the canals and dams that supply water to the Central Valley.

Standing next to Trump during the signing ceremony were five California House Republicans, including Denham.

Deputy Secretary of the Interior David Bernhardt hailed that move as “the most significant action taken by a president on Western water issues in my lifetime” during a conference call with reporters explaining the directive.

But some water-policy experts see Trump’s move more as politics than policy, as any action taken by the federal government won’t come until after the election.

“It was completely designed purely to throw a bone to the Central Valley competitive congressional races,” said Peter Gleick, a hydrologist and founder of the Pacific Institute.

Still, many farmers here in Stanislaus and San Joaquin counties, where irrigation canals and county roads crisscross cow pastures and stone-fruit groves for miles on end, are happy with any help they can get.

“Finally, after all these years he passed through a mandate to provide water infrastructure in the Western United States,” said David Phippen, a third-generation almond grower in Manteca who supports Denham. “We’ve been waiting a long time for that.”

The latest water struggle involves the California State Water Resources Control Board, which is set to decide whether to allow more water to flow through the San Joaquin River and its tributaries.

With freshwater more plentiful now that the Sierra Nevada have been replenished with snow, the plan is to provide more cool and quick-running water downstream to stave off the collapse of the chinook salmon and three-inch delta smelt. But farmers fear it would leave them with less water to grow crops. The five-member panel will vote on the plan one day after Election Day.

In the midst of the controversy, Trump is staying away from nail-biter races like Denham’s, where his presence may hurt rather than help.

Instead, Denham helped bring three Trump Cabinet officials — Interior Secretary Ryan Zinke, Agriculture Secretary Sonny Perdue and acting Environmental Protection Agency chief Andrew Wheeler — to the Central Valley in recent months to tour reservoirs and talk with growers.

During a visit to the Don Pedro Reservoir in July, Zinke praised the congressman’s “great leadership” on water issues.

The visits prompted both Interior and the EPA to later send California’s water board letters questioning whether allowing more downstream flows is legal or even if it would help dwindling fish populations.

Almond farmers like Phippen, who oppose what they call the state’s “water grab,” are sensitive to perceptions that they grow a thirsty crop. During the height of the drought California’s almond industry lamented what became an oft-heard statistic: That it takes about one gallon of water to produce a single almond.

While riding around his sprawling 70-employee farm, which processes about 35 million pounds of almonds every year, Phippen noted that the nearly four-story tall mounds of almond hulls stored in an open-air barn will not go to waste.

Gesturing to a semi being loaded with hulls, Phippen said, “Tomorrow morning, it’ll be milk.” The outer coverings were on their way to be fed to dairy cows.

Bob and Margo Cushing, almond ranchers about 20 miles to the east, emphasized what they and others see as an even greater threat: The Brown administration’s proposal to construct two massive tunnels under the delta to bring water south.

The Cushings, however, back Harder. They and other supporters of the Democratic nominee fret over Denham’s vote in favor of an appropriations bill that included a prohibition against any lawsuits being brought against the controversial tunnels.

“That didn’t help us at all,” Bob Cushing said while leaning against his John Deere Gator at his 11,000-tree orchard in Oakdale outfitted with low-volume sprinklers between trees to conserve water.

The Denham campaign counters by casting Harder, a former venture capitalist, as “Bay Area Harder” after he failed to attend a Sacramento rally against the state’s “water grab.”

The Republican’s camp also tried to use Harder’s endorsement from the League of Conservation Voters, which is spending about $100,000 in get-out-the-vote efforts for Harder, against him after the group derided Trump’s water memo as “a political stunt.”

But the coup de grace for Denham was Trump’s signature in October on a water infrastructure bill the congressman helped write. The bill authorized financing for new water storage projects across the Western United States. Again, Denham stood at Trump’s side while signing.

Harder derided the bill as “grandstanding,” saying it “doesn’t appropriate a single dollar of federal funding for any water project.”

“It’s a bill that you can go home a week before election and tell people you did something,” Harder said.

But the farming establishment here in Stanislaus and San Joaquin counties, thrilled to finally see the federal government taking their concerns seriously, is sticking with Denham. The counties' two farm bureaus both back the incumbent.

Farm owners are not the only ones who depend on water. Much of the Hispanic community here, which makes up 40 percent of the district’s population according to the 2010 Census, works in agriculture.

“If we can get them to vote, that’s our biggest challenge,” said Guadalupe Villarreal, a retired walnut farmer and Harder supporter. “A lot of these people don’t typically vote.”

At an intersection down the road from Phippen’s almond operation, a half-dozen Democratic campaign volunteers stood in the late-day sun to wave pro-Harder signs, some of which were emblazoned with water towers.

“Water is not an issue in a lot of places,” said Kathi Fotinos, a retired nurse campaigning that day. “But we’ve gone from one drought to the next.”

Suddenly, a motorist gave an indication that Harder’s message on water was breaking through.

Out of the window of a passing pickup truck a woman yelled: “Save our water! Vote for Josh Harder!"

Juliet Eilperin contributed to this report.