The Senate easily defeated an attempt by Sen. Rand Paul (R-Ky.) on Thursday to strip money from Planned Parenthood, with Democrats holding together unanimously despite the prospect of election-year attacks from Republicans over the issue.

Those attacks arrived mere moments after the vote closed, with the National Republican Senate Committee blasting out releases attacking Sens. Joe Manchin III (D-W.Va.), Joe Donnelly (D-Ind.) and Heidi Heitkamp (D-N.D.) for opposing Paul’s measure. The three are among the most endangered Democrats in the Senate.

“Manchin votes to fund abortion providers,” read the news release targeting Manchin, who like the others is fighting for survival in November in a state that voted overwhelmingly for President Trump. His office had no immediate response.

The vote on Paul’s amendment was 45 “yeas” to 48 “nays,” with moderate Republican Sens. Susan Collins of Maine and Lisa Murkowski of Alaska joining Democrats in voting no. Sixty votes would have been required to pass the amendment, which would have ended federal funding for Planned Parenthood, even though the group is already prohibited from using federal funds for abortions.

Democrats disputed any political downside from the vote.

“Every Dem voted to protect funding for Planned Parenthood, which is highly popular. The main upshot (goal?) of this vote: Collins/Murkowski using it to act like they are solidly pro-choice even as they defend a potential vote for anti-Roe Kavanaugh,” said a Twitter post from Brian Fallon, executive director of Demand Justice, an advocacy group fighting the Supreme Court nomination of Brett M. Kavanaugh and other conservative judicial nominees. Roe v. Wade was the 1973 Supreme Court decision that legalized abortion.

The failure of the Paul measure was expected, although whether it would come to a vote at all had not been certain. Senators had spent hours squabbling behind the scenes over what amendments would get votes on the legislation that was the main event of the week: a massive spending package wrapping appropriations for the Department of Defense with spending for the Departments of Labor and Health and Human Services and other related agencies. All told, funding in the package comprises 65 percent of all federal discretionary spending.

The bipartisan two-bill package passed 85 to 7. The Senate has now approved nine of 12 annual spending bills that must pass to keep the government funded, a much faster pace on appropriations bills than the Senate has achieved in recent years.

Senators are highly motivated on the issue: Government funding runs out Sept. 30, and Trump has already threatened a shutdown if Congress sends him another massive “omnibus” spending bill — as happened earlier this year — that wraps all the separate appropriations bills together.

However, much of the hard work remains to be done, because even as the Senate has been passing bipartisan bills, the House has been passing partisan legislation with only Republican votes that include policy provisions on environmental and other issues opposed by Democrats. Senators and House members will have to come to terms on those bills, work that will start in earnest after Labor Day, when House members, who have been away from Washington on an extended August recess, return to Capitol Hill.

Among the thorniest outstanding issues: How much money will be dedicated for Trump’s border wall, and how to pay for a new veterans health program without busting agreed spending caps.

The legislation passed Thursday includes a large funding increase for the Pentagon as well as increased funding for the National Institutes of Health, and increased resources for opioid treatment and recovery. The domestic spending levels, which were agreed to in an earlier deal, are much higher than the Trump administration supports but were the result of a deal in which Democrats agreed to big spending increases for the Pentagon in exchange for GOP support for domestic spending increases.

“This package is extremely important to the security and prosperity of this nation,” said new Senate Appropriations Committee Chairman Richard C. Shelby (R-Ala.). “For the first time in a dozen years, we are in a position to send a defense appropriations bill to the president on time — one that continues to rebuild our military and gives them the support they deserve. The legislation also provides a significant increase in funding to advance medical research, improve rural health care and fight the opioid crisis.”