A closely divided Senate on Monday blocked a proposed federal ban on abortions after 20 weeks in a vote that is likely to be the first of several ­election-year attempts to highlight the split between Democrats and Republicans.

The Pain-Capable Unborn Children Protection Act failed to earn the 60 votes needed to clear a procedural hurdle, marking a defeat for opponents of such procedures but fulfilling a pledge by Senate Majority Leader Mitch McConnell (R-Ky.) to hold a vote on the legislation. The vote was 51-46.

McConnell said the legislation "reflects a growing mainstream consensus" that abortions should be banned after 20 weeks.

"There is no reason why this should be a partisan issue," he added. "I hope that my Democratic colleagues will not obstruct the Senate from taking up this bill."

But only three Democrats — Sens. Robert P. Casey Jr. (Pa.), Joe Donnelly (Ind.) and Joe Manchin III (W. Va.) — voted with 48 Republicans to advance the measure. The senators have supported similar bans in the past and are facing reelection this year in states that President Trump won in 2016.

Two Republicans — Sens. Susan Collins (Maine) and Lisa Murkowski (Alaska) — joined 44 Democrats and independents in voting against the bill. Sen. ­Dianne Feinstein (D-Calif.) said the legislation is "yet another attempt to harm women by criminalizing their health care." She criticized Republicans for spending "the Senate's time trying to turn back the clock" rather than focusing on a Feb. 8 spending deadline and bipartisan attempts to compromise on immigration.

But Sen. Shelley Moore Capito (R-W.Va.), who voted for the bill, said holding election-year votes on bills tied to divisive issues is the reality of the modern Senate.

"I think every leader, no matter if it's a Republican or a Democrat, is going to have these kinds of votes," she said at a Washington Post Live event on Monday. She defended McConnell's decision to hold the vote, saying, "he's only bringing it up one night, we're not having a big debate on it. It will not pass."

Appearing alongside Moore Capito, Sen. Angus King ­(I-Maine) said such votes are part of the "downward spiral" of the Senate. He voted against the bill because "ninety-nine percent of abortions take place before 20 weeks, so this is a solution in search of a problem."

In a statement, President Trump called it "disappointing that despite support from a bipartisan majority of U.S. Senators, this bill was blocked from further consideration."

Only 1.2 percent of abortions are performed after 21 weeks of pregnancy, according to the Guttmacher Institute, which researches abortion and was founded by Planned Parenthood. All but seven states prohibit some abortions after a certain point in pregnancy, making many late-term abortions rare and largely banned already.

The House passed the legislation 237 to 189 in October; three Democrats voted yes while two Republicans voted no.

Public opinion on 20-week abortion bans is evenly split. A January 2017 Quinnipiac University poll asked whether people would support such a ban if it were enacted in their state: ­Forty-six percent supported it while 46 percent opposed it. Nearly six in 10 Republicans supported the ban, while nearly six in 10 Democrats opposed it — a notable partisan divide.

American views on the legality of abortion generally has remained steady in recent decades where nearly six in 10 Americans say abortion should be legal in all or most cases, while four in 10 say it should be illegal in all or most cases.

Russell Moore, the president of the Southern Baptist Convention's lobbying arm, says he has felt more energy from the Republican leadership on the issue than he has in recent years.

The antiabortion movement has had a "resigned fatalism" in years past, Moore said, but it has recently had a "shot in the arm," and antiabortion activists have focused on the question of late-term abortions.

"Members of Congress have been wrong to assume that people will simply get over their convictions about abortion," Moore said. "That would be something I'd be weighing very carefully if I were representing a purple-ish state."

Scott Clement and Sarah Pulliam Bailey contributed to this report.