ALBANY — New York’s final state budget will sweeten retirement benefits for public workers hired after 2012, allowing teachers to retire at age 58 and other workers to contribute less toward the pension system, a source with the Hochul administration told Newsday.

Police and firefighters also would get to count more of their overtime earnings toward their pension benefits under deal, the source said.

The changes mark a major win for the state’s unions in an election year.

They come with a $557 million annual price tag. The bulk of which, $440 million will be borne by local governments and school districts — and their taxpayers. The state’s share is $118 million.

Virtually every state and local government worker will be affected, including teachers, firefighters, police and health care workers at public hospitals such as Stony Brook University Hospital and Nassau University Medical Center.

The changes will affect the approximately 787,241 workers who were hired on or after April 1, 2012 in what is known as Tier 6.

The tier was created as lawmakers looked to tame fast-rising retirement costs and, as a result, its members currently receive fewer benefits, must wait longer to retire with full benefits and contribute more toward their pensions.

The retirement sweeteners, aimed at attracting and retaining workers, are part of the state’s approximately $268 billion state budget, which was due April 1. Lawmakers have approved three of 10 budget bills and are expected to finish voting next week.

Under the final deal, teachers will be allowed to retire at age 58 with 30 years of service, according to the source from Gov. Kathy Hochul’s administration.

Other state and local public workers, excluding teachers, will see a decrease in their contribution rates with 3% being the lowest and 5.75% being the highest, the source said. Contribution rates vary, with those earning more generally paying more.

The budget also will increase the amount of overtime pay that counts toward pension benefits to 25%, up from 15%, for those in the state police and fire retirement system.

And it will increase the cap on the amount of overtime pay included in pension calculation from approximately $22,000 to $30,000 — a change that will largely benefit state and local corrections officers and county deputy sheriffs.

The overtime changes also apply to workers in what’s known as Tier 5, who were hired from Jan. 1, 2010 through March 31, 2012.

There are approximately 38,873 Tier 5 workers statewide, according to the most recent data.

The changes would not generally affect members of the NYPD or FDNY pension funds because new members are generally considered Tier 3, and the city retirement systems don’t include Tier 5.