RICHMOND — The battle over Medicaid expansion bogged down the budget process once against Thursday as Republicans worked to ensure — as best they can — that Gov. Terry McAuliffe can’t expand the program on his own once the legislature leaves town.

Back and forth over budget amendments to that end delayed the legislature for hours as Senate Republicans debated the issue amongst themselves and House Republicans pushed for the changes.

Senate Republican Leader Tommy Norment, R-James City, said it was his most challenging night in 23 years at the General Assembly. He likened it to threading several moving needles at once as he tried to strike a balance his party's more conservative and moderate elements could embrace in a week that has seen a series of shakeups in Virginia politics.

The state senate eventually passed a budget, with the amendments in place, shortly after 11 p.m. The vote was 21-18.

The House followed suit shortly before midnight, 69-31.

Two Democrats, state Sen. Lynwood Lewis of Accomack, and Del. Johnny Joannou, of Portsmouth, crossed the aisle to vote the amended budget through with the Republican majority. Joannou often votes with Republicans. It wasn't immediately clear why Lewis did, and he waved away an interview request while talking on his cell phone after the vote.

Lewis voted against amending the budget, but once it was amended, he voted for the budget itself.

McAuliffe has played it coy about whether he’ll try to expand Medicaid - his top priority - by some sort of executive action. But many expect him to, especially now that a long legislative push to include expansion in the state budget has failed. A written statement he put out after Thursday's votes blasted Republicans for putting a "narrow ideology ahead of what is best for our families, economy and budget."

“When this budget reaches my desk I will evaluate it carefully and take the actions that I deem necessary, but this fight is far from over," McAuliffe said in his statement. "This is the right thing to do for Virginia, and I will not rest until we get it done."

Senate Democratic Leader Richard Saslaw echoed that as he left the Senate chamber and headed for the governor's mansion after midnight.

"Anything can happen," he said.

But, in arguing against the amendments Republicans tacked into the budget, Saslaw said they would block expansion for at least two years. Other Democrats agreed. Republican senators denied it even as they fought to include the amendments.

The amendments remove language first inserted into last year's budget, and brought forward into this year's budget document by former Gov. Bob McDonnell's administration.

That language would have allowed funding for expansion - which would extend taxpayer supported health care to hundreds of thousands of poor Virginians - if a commission that the assembly set up last year approved expansion first.

That commission, stacked with Republican opponents, has been blocking expansion.

State Sen. Richard Black, a Leesburg Republican who recently made headlines for writing a letter of support to Syrian dictator Bashar al-Assad, filed the first amendment Thursday in an effort to specifically forbid the governor or the commission from okaying expansion without an express vote from the full General Assembly.

The Senate's narrow Republican majority – made a majority earlier this week by the surprise resignation of Democratic state Sen. Phil Puckett – eventually coalesced behind a very similar amendment from state Sen. Bill Stanley, R-Moneta.

Though the amendments came up in the Senate, they were pushed by House Republicans who pressed their large numbers advantage to safeguard against expansion.

It's not clear that the governor has this power now, but the intent is to make the legislature's position obvious, particularly if the issue ends up in court, according to Republican state Sen. Tom Garrett, who is an attorney.

Partisans on both sides disagreed about just what the amendment that passed will do. Several Republicans called it innocuous, with little impact since they believe McAuliffe can't expand Medicaid on his own, regardless of the amendment.

But Democrats in both chambers said it would kill Medicaid expansion for at least two years - the totality of this new budget cycle.

State Sen. Emmett Hanger, a Mount Solon Republican who fought alongside Democrats for months in favor of a quasi-privatized expansion option, said the governor has options despite the amendment. He can leverage his veto power in the budget or call the legislature back repeatedly to talk expansion, Hanger said.

House Republicans have said they're willing to have that debate, but House Majority Leader Kirk Cox and House Appropriations Chairman Chris Jones made it clear Thursday night that they and others in their caucus are against expansion for a number of reasons.

There was little optimism in that route Thursday for Democrats who had pushed hard to include expansion in this budget, and who once threatened to take this battle well past the July 1 start of a new fiscal year.

They didn't have the numbers to push that fight this week. After Puckett resigned, Hanger and fellow Republican state Sens. Walter Stosch and John Watkins sided with their own caucus to amend and pass the budget. All three had worked with Democrats on the MarketPlace Virginia plan for months, seeking a way to tap billions in federal expansion dollars to help provide health care for poor Virginians.

All three said they saw little choice Thursday but to swallow that effort for now. Going past July 1 without a budget wasn't an option because it would have hurt the state's bond rating and forced deeper cuts in an already austere budget, they said.

Sticking with Democrats to pass a budget without Medicaid expansion, but also without the GOP amendments to further block expansion, wasn't much of an option, Hanger and Watkins said.

"We had been provided a pretty good assurance that then the budget wouldn't pass the House," said Watkins, R-Midlothian.

"The House was prepared to shaft the bill," Hanger said. "We could have called their bluff. I guess we'll be second guessing that for a while."

Cox and other House leaders, who for months accused Democrats of holding the budget hostage over Medicaid, said they never made a specific threat Thursday.

"We certainly had members concerned," Cox said. "It's hard to speculate what the vote would have been."

Cox said his caucus was split between legislators who felt the amendment wasn't particularly needed and those who felt that McAuliffe's continued unwillingness to say whether or not he'll try to expand Medicaid by fiat necessitated it.

As for the underlying budget, it is much more austere than anyone thought it would be several months ago.

The reason? A tough couple of months in state revenue collections. McAuliffe's office said Thursday that May revenues showed the worst one-month decline the state has seen in 13 years.

As a result, most of the spending increases planned in the two-year budget legislators planned to pass was gone.

Public schools will get a bit more money to help cover enrollment growth, and some other funding increases survived, but for the most part, state funding for local governments and state agencies will stay where it was this year.

And the Opportunity Educational Institution, the state's takeover vehicle for failing schools, which a Norfolk judge ruled unconstitutional this week, was zeroed out.

Legislators also cut new money they had set aside for hospitals, in part to make up for the much larger amounts hospitals would have seen from Medicaid expansion. They cut out planned pay raises, including raises for sheriff's deputies and other hard-to-fill positions.

Given that Medicaid expansion was expected to save the state some $225 million over the next two budget years - largely due to lower indigent care bills - some questioned whether the changes really had to be so severe.

The cuts mean no new money for the Thomas Jefferson National Accelerator Facility, which had hoped to get $4.6 million over the next two years to help it win a U.S. Department of Energy electron collider project.

Also gone: $1 million local legislators had hoped to see to buy land around Langley Air Force Base and $4.4 million for a similar project around Naval Air Station Oceana.

The Jamestown-Yorktown Foundation won't get the roughly $560,000 in new funding it was hoping for next year, and the Hampton University proton cancer therapy project won't get the $980,000 in new state funding it was angling for over the next two years.

There was good news for the Wallops Island Flight Facility, though. Legislators decided to keep $5.8 million in the budget for a dedicated runway for unmanned aircraft, taking the money from the state's transportation trust fund.

Local legislators expressed disappointment in the budget changes, but the cuts are consistent with hits state funded programs are taking across the commonwealth.

“Disappointed that the Langley money is not included in the budget,” said Del. Gordon Helsel, R-Poquoson. “I understand why.”

Before the amengment wrangling began on the Senate floor Thursday night, it cleared the Senate Finance Committee easily despite a heavy Democratic presence on that committee - a sign that Democrats may have been blindsided by the GOP amendments later in the day.

State Sen. Mamie Locke, D-Hampton, was the lone no-vote in committee.