The federal government shares the overall cost of Medicaid with the states; the program covers about 75 million Americans, or 1 in 5. About 11 million of them were able to enroll as a result of states’ decisions to expand the program under the Affordable Care Act. Republican attempts to repeal the health law last year would have largely undone the Medicaid expansion and caused most of the new recipients to lose their coverage.

Virginia’s House of Delegates voted to approve Medicaid expansion during the regular 60-day legislative session that ended in March. But the Senate, whose members were not up for re-election last fall, remained opposed. Lawmakers failed to pass a state budget then because of the issue.

“That is debt, and I have four kids who are going to be having to pay for that for the rest of their lives,” Senator Amanda Chase, a Republican from Chesterfield, said of the federal funds spent on Medicaid expansion, explaining her vote against it on Wednesday. “It’s not just a fiscal burden, but it’s not the best solution for people who want real, quality health care.”

The turning point came in April when State Senator Frank Wagner, a Republican from Virginia Beach, said he had changed his position and would support Medicaid expansion, joining one other Republican, Senator Emmett W. Hanger Jr. of Augusta, and all 19 Senate Democrats. Mr. Wagner changed his mind after a work requirement was added to the plan.

Two other Republican state senators, Ben Chafin and Jill Holtzman Vogel, also voted for Medicaid expansion on Wednesday.

“I came to the conclusion, for me and my district, that no just wasn’t the answer any longer,” Mr. Chafin. who represents an economically struggling district in southwestern Virginia, said on the Senate floor. “Doing nothing about the medical conditions, the state of health care in my district, just wasn’t the answer any longer.”

The approval did not come without last-minute drama: Thomas Norment, the Senate majority leader and steadfast opponent of Medicaid expansion, tried unsuccessfully to block it in the Senate Finance Committee on Tuesday, and again on the Senate floor on Wednesday, when he pushed to pass a version of the budget that did not include it. Instead, a substitute budget including amendments that allowed for Medicaid expansion, offered by Senator Hanger, was approved.