WASHINGTON — Democratic presidential contender Elizabeth Warren has been on a run in the last three months — moving up in the polls, raising nearly $20 million for the fundraising quarter and standing out in her first debate.

But now that the Massachusetts senator seems to have a legitimate chance to win the nomination and capture the presidency, Democrats will have to grapple with this possibility: A Warren presidency could cost the party a Senate seat — at least in the short term.

The same prospect is true if Sen. Bernie Sanders, I-Vt., wins the White House.

And either situation could complicate the math for Democrats to win control of the Senate, which would be crucial if the party wants to enact many of the ambitious policies its presidential hopefuls are proposing.

Republicans currently hold a 53-47 majority in the Senate. So to win back the chamber in the 2020 elections, Democrats will need net a pickup of three seats if they win the White House — and four if they don’t, since the vice president casts the tie-breaking vote.

Here’s the problem for Democrats: Both Massachusetts and Vermont have Republican governors who have the power to name a temporary replacement to fill Warren’s or Sanders’ vacant Senate seat with a Republican replacement. (Vermont’s governor, Phil Scott, is up for re-election in 2020.)

The other Democratic senators running for president — Kamala Harris (Calif.), Amy Klobuchar (Minn.), Cory Booker (N.J.), Kirsten Gillibrand (N.Y.) and Michael Bennet (Colo.) — all hail from states with sitting Democratic governors.

Then there’s the delay: Under Massachusetts state law, the governor must call for a special election 145 to 160 days after the vacancy — which means a Democrat, if he or she wins the special election, might not claim the Senate seat until months after a Warren presidency begins.

In Vermont, the special election takes place within six months of the vacancy.

Being temporarily without a Democratic senator in Massachusetts or Vermont could endanger the new president getting Cabinet secretaries confirmed and early legislative priorities passed.

It also could postpone Democrats taking control of the Senate — if they net the three Senate seats needed to flip the chamber, but briefly lose either Massachusetts or Vermont.

And then there’s the potential worst-case scenario: While Democrats would be favored to win the eventual special election in either of these deep-blue states, it was less than a decade ago when Republican Scott Brown won a special Senate election in Massachusetts after Ted Kennedy died in Barack Obama’s first year as president.

Warren defeated Brown two years later to claim the seat.

“It would impact Senate math,” says Jennifer Duffy of the nonpartisan Cook Political Report, referring to Warren or Sanders winning the presidency.

“The question is: What is the likelihood of that scenario coming to pass?”

The Warren campaign declined to comment for this article, while the Sanders campaign refused multiple opportunities to comment.

How Democrats could work around a Warren vacancy

Yet there is a possible workaround in Massachusetts that could shorten the window for a Republican appointment and a special election if Warren becomes president.

Under state law, an outgoing senator could file a letter of resignation, triggering the 145- to 160-day period to hold a special election — but not make the resignation effective until a later date.

So Warren could file that letter the day after Election Day — or even earlier during the general-election campaign — to expedite the date of the special election and minimize the time of any Republican replacement.

This scenario was floated when Warren was a vice presidential possibility for Hillary Clinton in 2016.

Clinton ended up picking Sen. Tim Kaine, D-Va., as her running mate.

Massachusetts’ long, complicated history with its Senate succession law

How Massachusetts fills vacant Senate seats has been a frequent topic of attention, and revision, over the last 15 years.

In 2004, after Sen. John Kerry became the party’s presidential nominee, state Democrats changed the law from allowing the governor to fill a Senate vacancy until the next state election to mandating a special election.

That change was designed to prevent then-Gov. Mitt Romney, a Republican, from picking a member of his own party to fill the seat (which never happened because Kerry lost the general election).

Then, in 2009, Democrats changed the law again, tweaking it to enable then-Gov. Deval Patrick, a Democrat, to temporarily appoint someone to the seat before the special election — to ensure the party didn’t lose a Senate vote after Kennedy died.

That’s the current law on the books if Warren’s seat becomes vacant.