The visitors dominated early possession and almost took the lead through Chris Millar but his long-range effort was saved well by Dan Twardzik.
And despite Josh Law drawing a save from Alan Mannus, St Johnstone continued to press with Millar, Gary McDonald and Scott Brown all going close.
Paul Lawson almost scored for Motherwell just before the break and the home side created an early opportunity after the interval but John Sutton was denied by Mannus.
Sutton then had a gilt-edged opportunity to break the deadlock but Mannus was equal to the task as he saved the Motherwell forward’s point-blank header.
St Johnstone were inches away from taking the lead in the 69th minute but Michael O’Halloran saw his long-range effort from an acute angle strike the post.
Graham replaced Steven Maclean 15 minutes from time and on 86 minutes he made the decisive contribution of the game.
McDonald swung a corner into the penalty area and Graham leapt above everybody else to power his header into the bottom right corner of the net.
Lee Erwin fashioned a couple of chances late on for Motherwell but St Johnstone held on for a win which sends them up to fourth in the Scottish Premiership.