RICHMOND — Rep. Dave Brat, the Republican upstart who toppled then-House Majority Leader Eric Cantor four years ago, is in a tight race with Democrat Abigail Spanberger, according to a new poll.

Spanberger, a former CIA officer and political newcomer, leads Brat 47 percent to 42 percent among all potential voters, according to a Monmouth University poll released Tuesday. Two percent favor Libertarian Joe Walton, and 9 percent are undecided.

Spanberger’s lead shrinks when the poll applies two different models to the race in Virginia’s 7th Congressional District, a mix of suburban and rural territory in the central part of the state that stretches from Culpeper to Nottoway County.

The candidates are tied at 47 percent when the survey assumes turnout will follow historical norms for midterm elections. Spanberger leads 48 percent to 45 percent — a statistically insignificant margin — when the model projects a Democratic surge.

The poll finds Spanberger with a hefty advantage in the Richmond suburbs, where President Trump’s sagging popularity is thought to be a drag on the Republicans. Spanberger leads Brat 58 percent to 30 percent in Henrico County, where Trump was soundly defeated in 2016. She leads 50 percent to 35 percent in Chesterfield County, which Trump narrowly won.

But Brat leads in rural areas, where Trump remains popular, by a margin of 57 percent to 35 percent.

“This is a tale of two districts,” said Patrick Murray, director of the Monmouth University Polling Institute. “The Richmond suburbs that backed Clinton in 2016 support Spanberger, while the Trump strongholds are firmly behind Brat. The reason this race is so close right now is because there are more voters in the suburban areas.”

Brat was a little-known Randolph-Macon College economics professor four years ago when he beat Cantor in the GOP primary, a stunning upset fueled by an ascendant tea party. He won reelection two years ago by 16 percentage points.

This year, Brat is contending with a strong challenge from Spanberger, who could benefit from anti-Trump sentiment in the district’s suburban areas and lingering resentment that Cantor supporters have for Brat. The Cook Political Report classifies the race as a “toss-up.”

The 7th District has long been considered solidly red, but Republicans have seen their margins shrink in recent statewide elections. As currently drawn, the district favored Republican Mitt Romney over President Barack Obama by 11 percentage points in 2012. In 2016, Trump won the district by six points. In the 2017 governor’s race, Republican Ed Gillespie beat Democrat Ralph Northam by four points.

The telephone poll of 400 potential voters was conducted from Sept. 15 to Sept. 24. It has a margin of error of plus or minus 4.9 percentage points for the full sample and plus or minus 5.4 percentage points for the likely-voter models.

Another poll released this week also found the race tight. Brat was ahead 47 percent to 43 percent in the New York Times Upshot-Siena College poll, which surveyed 501 likely voters. His lead was within the margin of error, which was plus or minus 4.3 percentage points.

In the Monmouth poll, white voters without a college degree favor Brat 61 percent to 31 percent, while college-educated whites back Spanberger 52 percent to 41 percent. Nonwhite voters, regardless of education, support Spanberger 68 percent to 9 percent.

Fifty-six percent of voters said they have a lot of interest in the election, which will help determine control of the House. The district’s voters are split on which party they prefer, with 39 percent favoring Republicans, 37 percent seeking a Democratic takeover and 20 percent with no preference.

The poll finds that Spanberger, who has sought to appeal to swing voters and Republicans by playing up her background in national security, has more cross-party appeal than Brat. While 83 percent of self-identified Republicans said they will vote for Brat, 13 percent say they will support Spanberger. Ninety-one percent of Democrats said they will vote for Spanberger; none said they would support Brat.

Independents were split at 45 percent for Spanberger and 36 percent for Brat.

“Some Republican voters who are lukewarm on Brat feel comfortable enough with Spanberger to give her their support, at least for now,” Murray said.

Voters rate Spanberger more positively than Brat. Forty-three percent view her favorably, 19 percent unfavorably, and 39 percent have no opinion. Brat’s ratings are 35 percent favorable and 27 percent unfavorable, with 37 percent having no opinion.

Voters in the poll are split on the job Trump is doing as president, with 47 percent approving and 46 percent disapproving. The 40 percent who strongly disapprove outnumber the 33 percent who strongly approve.

Trump critics are more likely than the president’s fans to say voting in the Brat-Spanberger race is an important way to send a message about their feelings toward the president. The poll found 70 percent of Trump opponents feel that way, while that’s the case for 64 percent of Trump supporters.