ALBANY, N.Y. — Lawmakers in New York state passed a $168.3 billion state budget in the early hours Saturday that includes surcharges on taxi, Uber and Lyft rides in Manhattan and a new state sexual harassment policy written following the #MeToo movement.

The massive spending plan also sets out $1 billion in new education spending, investments in New York City subways and upstate water quality, along with new disclosure rules for online political ads.

On taxes, the budget contains changes intended to soften the blow of the new federal tax code, which will raise tax liabilities for many New Yorkers.

It also contains one new tax — a fee on opioid manufacturers that will raise $100 million a year to combat addiction.

The spending plan was hammered out during negotiations between legislative leaders and Democratic Gov. Andrew Cuomo. This year’s work was complicated by a $4 billion spending gap and the desire to respond to new policies from the Trump administration. Lawmakers passed a budget just ahead of a critical deadline on Sunday, when a new state fiscal year begins.

“This budget was the most difficult budget that I think we have done,” Cuomo told reporters late Friday. “We started with a big deficit. We’re under attack by the federal government. To get it (the budget) done early was a herculean task.”

In his initial budget recommendation to lawmakers in January, Cuomo inserted several policy proposals, including ones to extend the statute of limitations on child molestation, authorize advance voting and eliminate cash bail requirements in low-level criminal cases. All were stripped out after running into opposition with the Republican leaders of the state Senate.

That upset many advocates and progressive groups who have long pushed for the changes. They are vowing to try again after special Senate elections next month in Westchester County and the Bronx that could hand Senate control to the Democrats.

“Once again the leaders of New York State have failed victims of child sexual abuse,” said Gary Greenberg, a leading supporter of the unsuccessful Child Victims Act, which would extend the statute of limitations for child molestation and create a one-year litigation window allowing victims to sue over potentially decades-old abuse. “We will find a Governor and legislators who will pass a Child Victims Act.”

The budget includes victories for both parties. Senate Republicans successfully pushed back Cuomo’s call for $1 billion in new taxes and fees. Assembly Democrats were able to insert a provision into the budget to create a legislative pay commission to examine whether to raise the legislative salary — now $79,500 — for the first time in nearly two decades.

“This budget invests in the shared priorities of hardworking New Yorkers – affordability, opportunity, and security. It is a solid and fiscally responsible budget that protects taxpayers, creates jobs, and supports many other quality-of-life issues important to middle-class families across the state.”

Cuomo scored victories too. The budget includes his proposal to help those negatively impacted by the new federal tax code, which caps a deduction for state and federal taxes that is especially popular in high-tax states such as New York. Cuomo’s plan creates tax credits for charitable contributions to public education or health care programs and allows employers to replace the income tax currently paid by employees with a payroll tax paid by the company. Salaries would be adjusted accordingly.

He also convinced lawmakers to include fees on taxis and ride-hailing services south of 96th Street in Manhattan — $2.75 for Uber, Lyft and similar services, $2.50 for taxis — to raise an estimated $415 million for subway repairs. It’s expected to be the first phase of a plan to impose tolls on all vehicles.

In a statement, Uber said it agrees with the congestion tolls, as long as they are ultimately applied widely: “It is the best way to fully fund mass transit and reduce traffic in the central business district.”

There was broad support for the sexual harassment policy, which will apply to all government officials and also provides new standards for the private sector. Cuomo said it was the first policy of its kind in the nation, though many Democrats wanted stronger protections.

“This plan is a strong first step,” said Assembly Speaker Carl Heastie, D-Bronx.

Many budget details weren’t known to the public until late Friday night — after lawmakers had begun voting. Negotiations were held behind closed doors, the bills were rushed to the floor and final votes were held in the middle of the night.

Republican Assemblyman Kevin Byrne decried what he said was a “startling lack of openness.”

“This is not the way state government should be run,” he said.