RICHMOND — Virginia lawmakers reached a deal Saturday on landmark legislation to legalize marijuana in 2024 as the General Assembly wrapped up an ambitious legislative session.

But the deal drew fierce pushback from legalization advocates, who said the compromise was worse than the status quo because, among other things, it requires the legislature to vote on aspects of the bill again next year, when Democratic control of the General Assembly and Executive Mansion is not a given.

The criticism added drama and uncertainty to the day as lawmakers scrambled to keep the massive legalization bill on track. But the House eventually passed the nearly 300-page measure on a vote of 48 to 43, with two abstaining, and the Senate followed suit with a 20-to-19 vote.

Last-minute wrangling on the marijuana bill capped six weeks of action on other big-ticket issues, including votes to make Virginia the first Southern state to abolish the death penalty, codifying sweeping changes to the state’s early-voting system and addressing the economic and social impact of the coronavirus pandemic.

Democrats, who control both chambers, pushed their agenda with an eye toward elections this fall, when their grip on power is at stake in contests for all 100 seats in the House of Delegates along with governor, lieutenant governor and attorney general.

And Gov. Ralph Northam (D), term-limited by the state’s constitution, pushed for action on marquee issues — including addressing long-term racial inequity — as he finishes his final year in office.

The compromise on marijuana legalization — and the criticism from legalization advocates — came as House and Senate negotiators worked to iron out disagreements between the two chambers that threatened to derail the high-profile effort.

“It was a lot of work to get there, but we’re on the path to an equitable law allowing for responsible adults to not be penalized for using cannabis,” Sen. Adam P. Ebbin (D-Alexandria) said.

The complex bill would make marijuana legal for adults to possess on Jan. 1, 2024, and begin retail sales on the same date. The legislation also would create a regulatory agency called the Cannabis Control Authority as of July 1 of this year, along with a new public health advisory council.

But the specifics of how the commercial marketplace would be constructed and overseen would have to be reenacted by the legislature next year.

At the same time, the measure provides for expungement of marijuana-related misdemeanor offenses and sets out a new plan for classifying drug-related crimes and a program of treatment and intervention instead of simple punishment. The exact nature of the criminal justice changes would also have to be reenacted next year by the legislature and then signed by the governor.

Those changes led to complaints among Democrats — as well as legalization advocates such as the American Civil Liberties Union of Virginia — that the measure was too slow and incomplete.

“By legalizing without all the guardrails in place, I feel the message can be misconstrued … that we have dropped the ball on the justice pieces,” said Del. Marcia S. “Cia” Price (D-Newport News). “Even the thought of business before justice is hard to stomach.”

But in the other chamber, Sen. Jennifer L. McClellan (D-Richmond) thanked Ebbin for taking a break in the proceedings to explain the deal in a slow and deliberate way. But she also hoped Northam would amend the bill to legalize marijuana before the date called for in the bill. “This bill is not marijuana legalization,” she said, adding that it sets up the framework “to get us to a path for legalization in 2024.”

Several Democrats said they hoped Northam would amend the bill and send a more complete measure to the legislature later this year. The General Assembly reconvenes every year to consider amendments and vetoes issued by the governor. A spokeswoman for Northam said he “looks forward to continuing to improve” the legislation.

The controversy nearly upstaged a long list of changes passed by the legislature this year. None was more dramatic than the vote earlier in the session to end capital punishment in a state that has executed more people than any other over the past four centuries. Northam had made the issue a priority and has promised to sign the bill into law.

Another significant change to criminal justice law failed late Saturday when Senate and House negotiators were unable to reach agreement on how to reduce the use of mandatory minimum criminal sentences. The House had passed a bill to repeal mandatory minimums for drug crimes, while the Senate would eliminate them altogether, except for the willful murder of a law enforcement officer.

Other areas that saw significant action during the session included:

● Racial equity across state government. The House and Senate passed a resolution declaring racism to be a public health emergency, another first for a Southern state and the top priority of the Virginia NAACP.

The resolution — which has headed to Northam’s desk — would require the Virginia Health Department to apply that lens to its study of health throughout the state; make permanent a commission that Northam appointed to find areas of racial inequity in state law; and require training for elected and state officials in how to recognize systemic bias.

Another measure passed by both chambers requires every state agency to craft a strategic plan for fostering equity and diversity in its staffing and performance of duties. Northam on Friday released a “ONE Virginia” plan that sets out tools and best practices to guide state agencies in creating their diversity plans.

● Gun control. Earlier in the session, the House and Senate passed legislation to prohibit people convicted of misdemeanor assault and battery of a family or household member from possessing a firearm for three years.

The legislature also had already approved bills to ban firearms at polling places and property that school boards own or lease, such as for administrative functions, outside of designated gun-free school zones.

On Saturday, both chambers agreed to a ban on firearms and explosives on Richmond’s Capitol Square, including the park outside the state Capitol and the state office buildings that surround it. The ban excludes state-owned parking structures and lists a host of people who are exempt, including retired police officers, security personnel, active-duty military members and fire marshals.

● Vehicle emissions and electric vehicles. The General Assembly voted to adopt the California emissions program for vehicles, a stricter set of pollution standards than those imposed by the federal government. The program also sets targets for sales of electric vehicles.

Virginia would join 14 other states and D.C. in adopting the standards. Maryland joined in 2007. If signed into law by Northam, the standards would go into effect for the 2025 model year.

Another bill passed by both chambers would create a fund to provide rebates of between $2,500 and $4,500 for residents who purchase an electric vehicle in the state after Jan. 1, 2022.

● Effects of the coronavirus pandemic. The virus has hung over every aspect of the session, from the distanced way the Senate met in the Science Museum of Virginia to the online-only daily meetings of the House.

Over the course of the session, the state greatly expanded its effort to distribute the vaccine. To help that along, the House and Senate passed a measure making more health-care workers eligible to administer doses.

Republicans came into the session aiming to turn up the heat on Democrats to get schools reopened, and a Republican bill requiring in-person classes sailed out of the Senate. As public pressure mounted and more teachers got vaccinated, House Democrats buckled down late in the session and produced a bipartisan bill to require all school systems to offer a full schedule of in-person instruction, with options for remote learning as needed, by July 1.

Other bills were aimed at workers in the fight against the virus. The House and Senate approved a measure requiring five days of paid sick leave for home health-care workers serving clients under Medicaid.

And on Saturday, both chambers completed approval of bills that would help front-line workers qualify for workers’ compensation if they were infected with the coronavirus while treating people who have it.

One bill, sponsored by Del. Chris L. Hurst (D-Montgomery), would presume that infections among health-care workers were job-related, which would be retroactive to the start of the pandemic.

Another, with versions sponsored by Del. Jerrauld C. “Jay” Jones (D-Norfolk) and Sen. Richard L. Saslaw (D-Fairfax), would let first responders such as firefighters and police have the same presumption, retroactive to Sept. 1. That measure contained a shorter time period to limit the potential cost for local governments.

● The state budget. The two-year spending plan is traditionally the last big-ticket item on the final day of session. This year, House and Senate negotiators reached a deal relatively easily; it passed overwhelmingly in both the Senate (29 to 10) and House (67 to 32) on Saturday. The plan calls for 5 percent pay raises for teachers and other state employees, as well as 8 percent raises for state police.

Fitting so many ambitious goals into the session required some fancy footwork with the calendar. The session convened on Jan. 13, and Republicans used a procedural move to limit it to 30 days, instead of the 46 that are customary for an odd-numbered year. So Democrats adjourned the regular session Feb. 8, and Northam called a special session that convened Feb. 10.

Lawmakers finished legislative work on Saturday and planned to officially adjourn on Monday.

Correction: An earlier version of this story incorrectly reported that Sen. Jennifer L. McClellan (D-Richmond) defended the marijuana bill the General Assembly passed as careful and deliberate. In fact, she was praising the patron of the bill for slowing down to explain the measure to senators before they voted. In addition, a nickname for Del. Marcia S. “Cia” Price (D-Newport News) was spelled incorrectly.