WASHINGTON—A bill criminalizing abortions performed after 20 weeks of pregnancy failed to advance in the Senate on Monday but forced Democrats up for re-election in competitive races to take sides on the contentious issue.

The legislation secured 51 votes, mostly from Republicans, shy of the 60 the bill needed to move forward. The three Democrats to support the bill—Sens. Joe Manchin of West Virginia, Bob Casey of Pennsylvania and Joe Donnelly of Indiana—all face re-election this fall and represent states that President Donald...