WASHINGTON -- The Senate voted Thursday to let states block federal family planning money from going to Planned Parenthood affiliates and other abortion providers.

Senators approved the Republican legislation 51-50. Vice President Mike Pence cast the tie-breaking vote after two GOP senators, Maine’s Susan Collins and Alaska’s Lisa Murkowski, voted with Democrats against the measure.

The bill erases a regulation imposed by former President Barack Obama that lets states deny family planning funds to an organization only if it is incapable of providing those services.

Get Breaking News Delivered to Your Inbox

Senate approval means the measure will be headed to President Trump, who was expected to sign it. The House voted its consent last month.

Some states have passed laws in recent years denying the funds to groups that provide abortions.

Democrats criticized the measure as an attack on women’s rights and abortion. Republicans defended it as a way to let local officials decide where family planning money should go.

Passage would give Republicans and anti-abortion groups a needed victory just six days after the party’s highly touted health care overhaul disintegrated in the House due to GOP divisions. Besides erasing much of former President Barack Obama’s 2010 health care law, the abandoned House bill would have blocked federal funds for Planned Parenthood for a year.

The Senate measure would roll back a regulation Obama issued shortly before leaving office. It bars state and local governments from denying federal family planning funds to organizations unless they are unable to provide those services. Some states have passed laws preventing abortion providers from receiving the funds.

There is already a ban on using federal funds for abortion except for rare instances.

Democrats assailed the legislation as an attack on women, two months after Trump’s inauguration prompted a women’s march on Washington that mushroomed into anti-Trump demonstrations around the nation.

“While Trumpcare was dealt a significant blow last week, it is clear that the terrible ideas that underpin it live on with Republicans in Congress,” said Sen. Patty Murray, D-Wash., using a nickname for the failed House health care bill. Murray, among a stream of Democratic women senators who spoke, called the Senate measure “shameful” and “dangerous.”

Republicans said the measure would give states more freedom to decide how to spend family planning funds. States would be free to divert money now going to groups that provide abortion to other organizations that don’t, like community health centers.

“It substituted Washington’s judgment for the needs of real people,” Senate Majority Leader Mitch McConnell, R-Ky., said of Obama’s rule.

With Republicans holding 52-48 control of the Senate, the Collins and Murkowski defections could have derailed the bill because Sen. Johnny Isakson, R-Ga., has been absent since Feb. 20, when he had spinal surgery.

He had a second operation March 15 and has been recuperating in Georgia under doctor’s orders. But he got permission to return to Washington for one day, his office said, and he did so using a walker.

“We didn’t know at the time what it would be but it turned out to be the vice president’s tie-breaker,” Isakson told reporters after the procedural vote.

The federal family planning program was created 1970 and in 2015 served 4 million clients at nearly 4,000 clinics. Most of the money is for providing services like contraceptives, family planning counseling, breast and cervical cancer screening and sexually transmitted disease prevention. It has a $286 million federal budget this year.

Most recipients are women, and two-thirds have incomes at or below the federal poverty level, around $12,000 for an individual. Six in 10 say the program’s services are their only or most frequent source of health care.

Dawn Laguens, executive vice president of the Planned Parenthood Federation of America, mocked Pence.

“Mike Pence went from yesterday’s forum on empowering women to today leading a group of male politicians in a vote to take away access to birth control and cancer screenings,” she said.

The Congressional Review Act lets lawmakers undo regulations enacted in the last months of the Obama administration with a majority vote. Congress has already used the law to eliminate Obama regulations that strengthened protections for streams near coal-mining operations and prevented some people with mental disorders from purchasing guns.

Under the Constitution, the vice president casts tie breaking votes. Pence broke his first tie on the nomination of Education Secretary Betsy DeVos.

Meanwhile, Maryland’s General Assembly has passed a bill to reimburse Planned Parenthood for Medicaid services in case federal dollars are cut off, CBS Baltimore reports.

“No federal funds go to abortion at all so all of them are preventive health services, so we’re talking basic health care,” said Joanna Diamond of Planned Parenthood.

“We just want to make sure our $25,000 or more women get to continue to have the Planned Parenthood services in the state of Maryland,” said Senator Nancy King (D-Montgomery County).

The bill shields Planned Parenthood with $2 million from the State’s Medicaid budget, and another $700,000 from the general fund should Republicans in Congress succeed in cutting off federal funds.

“We are very proud that our state legislature has stepped up,” Diamond said.