WASHINGTON — Bernie Sanders has been putting up major advertising cash to seize momentum heading into the Democratic presidential primaries — outspending his rival Hillary Clinton just as voters are beginning to pay attention to the race.

In the past three weeks, Sanders’ campaign has spent about $4.7 million on ads to Clinton’s $3.7 million, an investment that so far has meant 1,000 more Sanders commercials than Clinton ads on broadcast TV, according to advertising tracker Kantar Media’s CMAG.

The Sanders ad burst is coinciding with his rise in preference polls in Iowa and New Hampshire, the first two states where voters will weigh in on the 2016 election. The Democratic contest appears to be tightening.

Two recent surveys suggest Sanders has gained on Clinton in Iowa. In New Hampshire, one poll showed the Vermont senator ahead of the former first lady and secretary of state by double digits, while another pointed to a tighter race. Iowa votes Feb. 1; New Hampshire, Feb. 9.

Clinton began advertising in August, three months ahead of Sanders, and over the entire contest has outspent him by about $3 million, the CMAG data show. The ad buy data includes all broadcast, cable and satellite television, as well as some radio. It does not include digital ads.

The turnabout in ad spending — with Sanders topping Clinton in each of the past three weeks — prompted the Clinton campaign last week to send an email to supporters with the subject line “nervous.”

“I’m not trying to be dramatic about this (I swear! I’m really not!), but there’s a situation developing in Iowa and New Hampshire that could change the course of this election,” Clinton campaign manager Robby Mook wrote in the fundraising appeal. Later in the same email: “I just found out that he’s outspending us on TV advertising in Iowa and New Hampshire.”

In reality, both candidates have ample financial resources; each campaign said it had raised upward of $30 million in the final three months of the year.

This month, Sanders has aired nine different commercials. Two stand out for their heavy rotation.

His top-played ad of these past few weeks, “Working Families,” has been on some 1,200 times on broadcast stations, according to CMAG data covering Dec. 30 to Tuesday.

There’s nothing splashy or slickly produced about this 30-second commercial. The entire time, it’s footage of Sanders talking at a New Hampshire town hall meeting, delivering his typical remarks with his trademark exaggerated arm gestures.

“The bottom line of this economy is that it is rigged,” he says as people in the rapt audience nod their heads. “What this campaign is about is the demand that we create an economy that works for all of us rather than a handful of billionaires.”

Just behind that ad in frequency is one featuring a registered nurse in Vermont, Mari Cordes.

“Bernie Sanders understands how pharmaceutical companies and major medical companies are ripping us off,” Cordes says. “Bernie tells the truth, and he’s been consistent. He understands that the system is rigged, and he’s the only one that can bring real change.”

The ad includes an image of Sanders accepting the National Nurses United endorsement. That group has a super PAC that has been sending a “Bernie bus” around to early states to back him — despite his stated resistance to outside money.

One Clinton ad has aired as frequently in the past two weeks as either of those spots, CMAG shows.

Titled, “Wage Gap,” it posits that Republicans would “make it worse by lowering taxes for those at the top and letting corporations write their own rules.”

Clinton, the narrator says, would close the wage gap, push equal pay for women, a higher minimum wage and lower taxes for the middle class.

No Democratic candidate has called out a rival by name in TV ads. But with the race intensifying, the candidates are becoming more direct.

In an ad that began airing Tuesday night, Clinton says she supports the president’s call for universal gun background checks. “It’s time to pick a side,” she says, implying that she and Sanders are on different ones.

Sanders, in a CNN interview Tuesday night, said he agrees with the president. He said he, too, has an ad that implies he and Clinton differ — but on Social Security. In a forthcoming commercial, he said, he reminds voters he wants to raise Social Security benefits by lifting the cap on taxable income.

“We look forward to Secretary Clinton coming on board with that issue,” he said. Like Clinton, he does not mention his opponent in the ad, leaving it to voters to make the connection.

In total, Clinton has spent $16.6 million on ads and Sanders $13.4 million, according to CMAG. Sanders delayed starting his advertising to preserve funding for this critical period, his senior adviser Tad Devine said. “We intend to go toe-to-toe, or even exceed them, until the end,” Devine said of Sanders’ ad buys.

CMAG’s ad buy information shows Clinton with a larger spending plan over the next few weeks, although commercial space can be purchased with little lead time. She has reserved about $3.3 million in TV spots, and Sanders $1.7 million.

As the Republican side vividly illustrates, the size of an advertising buy doesn’t necessarily translate to voter support: Jeb Bush remains mired in preference polls despite having more money spent to promote his candidacy than anyone else in the 2016 field. The super PAC supporting him has plowed $52 million into ads.