ALBANY — New York lawmakers, having fallen short in a push to fully legalize marijuana, have agreed to further decriminalize possession of the drug and automatically expunge many low-level marijuana convictions across the state.

The measure, which would treat possession of up to two ounces of marijuana as a violation instead of a crime, is a significant change in a state in which tens of thousands of residents have been arrested for small-scale possession.

The agreement came after months of negotiations in Albany failed to establish the type of fully legalized industry embraced in nearly a dozen other states, including California, Washington and Alaska.

Still, the measure agreed to on Thursday by the Democrat-led Legislature, and backed by Gov. Andrew M. Cuomo, also a Democrat, was still considered a step forward for those pushing for lessening drug penalties, particularly the expungement of records.