The visitors took the lead through Ryan Strachan's strike from outside the area.
Declan McDaid's first Cowdenbeath goal levelled things, but Peterhead were ahead again just two minutes later, Leighton McIntosh tucking in from close range following James Redman's pass.
Jack Beaumont's free-kick made it 2-2, but Nicky Riley teed up Jamie Redman to lash home from inside the area.
Peterhead made it 14 league games without defeat by edging out Cowdenbeath 3-2.