In a step toward reshaping how all teachers in New York City’s 1,700 public schools are judged, the Department of Education and the city teachers’ union agreed on Friday to a pilot teacher-evaluation system that will take effect next year in 33 struggling schools.

The deal, which ended months of disagreement, was needed for the city’s continued participation in a federal grant program that could bring up to $65 million in grants — up to $6 million for some schools — over the next three years.

City officials announced months ago that they had applied for the grants for the 33