Patrick K. O’Neill, 62, of Philadelphia, a retired divisional deputy city solicitor for environmental law, avid outdoorsman, mentor, and lifelong conservationist, died Monday, April 18, of melanoma at home.

A skier, bicyclist, swimmer, and urban climber away from work, Mr. O’Neill spent more than three decades, starting in 1987, as an environmental attorney for the Philadelphia Law Department. He retired in March as a divisional deputy city solicitor after working two years in the 1980s in Harrisburg with the Pennsylvania Department of Environmental Protection.

A constant presence at meetings held by Philadelphia’s Department of Public Health, Mr. O’Neill was the city’s environmental counsel and public spokesperson on important issues such as pollution control, refinery and manufacturing safety, and demolition and renovation regulations.

“He was so committed to things other than himself,” said his wife, Ann Kreidle. “He was committed to be a good citizen.” In a tribute, his family said: “Patrick cared deeply for the planet and his adopted hometown.”

Over his 35-year career, Mr. O’Neill met with Philadelphia residents, tangled with lobbyists, and worked on programs that, among other things, addressed the city’s tree canopy, the development of city parks, electric vehicles at the airport, storm water management, and the harmful presence of asbestos and lead in buildings and nature.

He represented the city on advisory groups, worked closely with the Board of Health, and the Air Pollution Control Board, and championed efforts to educate the public about safety and health. “The asbestos program has worked diligently for the last 30 years to train folks to do things correctly,” he told those attending a meeting of the Air Pollution Control Board on Jan. 25, 2018.

Mr. O’Neill was a member and past president of the Delaware Valley Environmental Inn of Court. He mentored young lawyers, lectured about regulatory jurisdiction, and was active in continuing legal education programs for regulatory law.

In 2017, he won the Brown, Mulligan, Rocha Distinguished Public Service Award from the Maryland-based International Municipal Lawyers Association. He embodied “professionalism, ethics, civility, and excellence,” his family said.

Born June 3, 1959, in Dubois, Pa., Mr. O’Neill grew up near Norristown and graduated from Methacton High School in 1977. He was good at crafts and carving wood, considered becoming a shop teacher and attended Millersville University for a year.

But he transferred to Villanova and graduated in 1981 with an award for the best senior thesis in political science. He went on to graduate from Villanova’s Charles Widger school of law in 1985 and took a job in Harrisburg at the state’s department of environmental protection.

He went to City Hall because he had a vision of how government could protect the environment, his wife said, and he eschewed more lucrative jobs in the private sector to work for the public. “He said cities need people committed to their jobs,” she said.

Mr. O’Neill was adventurous and scaled the outside of nearly every building on the Villanova campus while he was in college. He was a tour leader for the Bicycle Club of Philadelphia, pedaled trails around the country, and even biked the roads in Croatia.

He met his wife on a bicycle ride, proposed to her at the top of City Hall, and they married in 1999. They lived in West Philadelphia and had sons Chris and Michael.

Mr. O’Neill was thrifty and took charge of the neighborhood on St. Mark’s Square, helping others clean their gutters and rake the leaves. He studied history and politics, and spent summers as a boy with his family and friends on the beach in Stone Harbor.

He worked long hours for many years at City Hall, and his family was delighted when he bought a BlackBerry so he could monitor his email from home. He liked to ski and swim and often whisked family and friends to slopes in Utah and lakes in northeastern Pennsylvania.

His family said: “He always had a twinkle in his eye and a funny observation to share.” His wife said: “He was a romantic through and through.”

In addition to his wife and sons, Mr. O’Neill is survived by other relatives. Two sisters died earlier.

A celebration of life is to be held at 5 p.m. Wednesday, June 1, at Arch Street Meeting, 320 Arch St., Philadelphia, Pa. 19106. A reception will follow. RSVP at https://pp.events/aarp43gw.

Donations in his name may be made to the Home and School Association of the Penn Alexander School, 4209 Spruce St., Philadelphia, Pa. 19104.