The city will spend $385 million to ensure all public schools have gymnasiums by 2021, Mayor Bill de Blasio announced Monday.

Over the next four years, the city will build gymnasiums at nearly 200 schools that either do not have them or are in dire need of an upgrade, de Blasio said at a news conference at P.S. 81 in Ridgewood, Queens.

“My pledge is that by September 2021 every single school in New York City will have a modern, full phys ed capacity for our children,” de Blasio said.

The mayor, joined by schools Chancellor Carmen Farina, said the lack of adequate gym space at dozens of city schools has kept those schools from fully complying with a state law passed in 1957 that mandates physical education for all students.

Under the law, schools must provide two hours of physical education each week for elementary school children, and 90 minutes for junior high and high school students.

A 2015 audit by City Comptroller Scott Stringer found that 435 city schools did not have a dedicated space for physical education.

De Blasio, using P.S. 81 as an example, said many of the city’s aging schools have been forced to use auditoriums and other inadequate spaces to hold physical education classes.

“Kids need phys ed for their bodies, but they also need it for minds. They need it for the ability to be calm and to focus and to learn,” de Blasio said.