He learned to swim at its beaches and grew up playing ball on its fields. Now Marty Maher is in charge of all the 877 park sites in Brooklyn.

The newly-appointed Brooklyn borough commissioner for parks — who has spent more than 30 years working his way up through the ranks of the agency — said he is committed to fostering the close relationship between New Yorkers and their beloved green spaces.

“Parks are a huge resource in this city,” said Maher, 53, of Windsor Terrace. “It’s where people go to exercise, reflect, take their children and grandchildren. There’s no better thing than taking a walk on the boardwalk or walking in Prospect Park.”

Parks Commissioner Mitchell Silver praised Maher’s “clear passion for public service” and “intimate knowledge of all things Brooklyn.”

“I’m confident that under his helm the borough parks will continue to shine,” Silver said.

Maher joined the parks department in 1984 as a parks enforcement officer at the urging of a friend. He had planned to join the Coast Guard full time and laughingly remembers picking up the application while wearing cut-off jeans and a T-shirt, never expecting to be called immediately for an interview.

“I figured I would see what training was like,” he said. “And that was it. Every time I thought about something else, I was promoted and got another challenge.”

He served as an inspector when parks were scarred by years of vandalism and poor maintenance.

“One of the great things is that I got to see the renaissance of parks and playgrounds and beaches,” Maher said. “The neighborhoods have embraced them and they have been given their own personality. All of that hopelessness and the graffiti is gone.”

Over the years, he supervised operations at Shea Stadium, Yankee Stadium, city marinas and beaches.

For the last 18 years, he has served as the chief of staff to the Brooklyn parks commissioner and been part of the ongoing effort to make parks reflect the changing needs of the city.

“When I was growing up, every field was for baseball or softball,” he said. “Now we have cricket fields, rectangular sports fields for soccer, field hockey, rugby and lacrosse.”

A Revolutionary War enthusiast, Maher takes a special interest in the borough’s historic sites and has even led colonial cooking classes.

“History is not something that’s far away,” Maher said. “Right here we had the Battle of Brooklyn — the largest battle of the American Revolution. People love finding out that stuff.”