After months of squabbling over how to pay for immigration-related legal services for undocumented immigrants convicted of crimes and facing deportation, Mayor Bill de Blasio’s office and the City Council came to a compromise on Monday.

City Hall had not wanted to use city money to benefit those convicted of one of 170 serious crimes, and under the agreement private donors will contribute $250,000 earmarked for their defense. That ensures that the New York Immigrant Family Unity Project, which since 2013 has represented indigent immigrants who have been detained, will continue to exist. That service will remain free, and the city will expand its resources to prioritize those who have not been convicted of the crimes.

The mayor’s office committed $16.4 million and the City Council committed $10 million for services provided by Brooklyn Defender Services, The Bronx Defenders and Legal Aid. The city requires law enforcement authorities to turn undocumented immigrants convicted of one of the 170 serious crimes over to immigration enforcement authorities, and in those cases, the three legal providers will use the money contributed by donors for their representation.

The mayor, in an appearance on NY1, said the money was provided by an anonymous donor from a foundation. A spokeswoman maintained that multiple foundations were involved.