WASHINGTON — The Senate rejected a bill on Monday to ban most abortions after 20 weeks of pregnancy, a largely symbolic vote aimed at forcing vulnerable Democrats to take a stand that could hurt their prospects for re-election in states won by President Trump.

By a vote of 51 to 46, the measure fell well short of the 60-vote threshold required for the Senate to break a Democratic filibuster. The outcome was not a surprise, and the vote fell mostly along party lines.

The Senate voted on a similar measure in 2015. At that time three Democrats — Senators Bob Casey of Pennsylvania, Joe Donnelly of Indiana and Joe Manchin of West Virginia — voted in favor of it. All three are up for re-election this year in states that Mr. Trump carried, and all of them voted in favor of the measure again on Monday. Two Republicans — Senators Susan Collins of Maine and Lisa Murkowski of Alaska — voted against it.

The bill, which has the strong backing of the Trump administration, is identical to one that passed the House in October and similar to legislation that has been adopted in 20 states. It would make nearly all abortions after 20 weeks illegal; anyone who performed the procedure could face a potential prison term of five years, fines or both, though exceptions could be made when the life of the mother was at risk, or in cases of rape or incest.