Maryland Gov. Martin O’Malley (D) on Thursday named John R. Griffin, a veteran of state government, as his next chief of staff.

Griffin, 66, will replace long-time aide Matthew D. Gallagher, 40, who is leaving the governor’s office in June to lead a philanthropic foundation in Baltimore. Gallagher’s departure was announced late Wednesday night by the Goldseker Foundation.

Upon his arrival in Annapolis in 2007, O’Malley tapped Griffin as secretary of the Department of Natural Resources, a Cabinet-level position he also held in the late 1990s under the state’s last Democratic governor, Parris N. Glendening. All told, Griffin has served in state government for more than 25 years.

“For the past six years he has been at the heart and soul of Maryland’s environmental agenda, lending his wisdom and expertise to the progress we have made in protecting and restoring our land, water, fish and crabs,” O’Malley said of Griffin in a statement. “His solid judgment and knowledge of state government will allow us to continue the progress we have made creating jobs, expanding opportunity and securing a better future for Maryland’s families.”

O’Malley said that Joseph P. Gill, Griffin’s deputy at DNR, will take over as secretary.

Griffin will become the third chief of staff for O’Malley, who is term-limited and must step down in January 2015.

Gallagher was preceded by Michael R. Enright, a childhood friend of O’Malley who held a similar post in Baltimore during O’Malley’s tenure as mayor.

“I am truly honored by Governor O’Malley’s confidence in me and am looking forward to working with him, his talented staff and cabinet in this new role,” Griffin said.