The head lawyer for the city, Zachary Carter, will be retiring at the end of August after working in Mayor Bill de Blasio’s administration for six years, officials announced Friday.

“It has been my privilege to lead the finest government law office in the country,” Carter said in a statement.

Carter, 69, was chosen for the position of the City’s Corporation Counsel in 2014 by de Blasio, then-Mayor elect, to oversee the nearly 1,000 city lawyers.

Carter — the former US Attorney in Brooklyn — will be temporarily replaced by current First Assistant Corporation Counsel Georgia Pestana while the city looks for a permanent replacement, the Mayor’s office said.

“Zach is one of our City’s finest public servants,” de Blasio said in a statement. “During his tenure, he has stood for fairness and equity, as is evident by his work settling with the Central Park Five and victims of the unconstitutional and unjust Stop and Frisk era.”

“He has moved our Law Department forward, and our City is better off for it,” de Blasio added.

In his retirement, Carter plans to focus on hobbies such as golf, music, writing, travel and volunteer public service, according to a Law Department spokesperson.

Manhattan District Attorney Cy Vance said Carter, “has made enormous contributions to the justice systems of New York City and the federal government.”