The Irishman scored with his right-foot, left-foot and head as Perth Glory moved, at least temporarily, to the top of the A-League table.
City came from behind twice in a sea-sawing contest that saw Kenny Lowe sent to the stands for abusing the referees at the half-time break.
However Keogh proved to be the hero in the 85th minute when he beautifully pounced on an error by City defender Josh Rose and lobbed goalkeeper Dean Bouzanis.
City had entered the match as favorites but Perth were unperturbed and opened the scoring in the 7th minute when Keogh finished off a precise set-piece move.
City struggled to create chances in the first half as Glory continued to soak up pressure, allowing little space for the likes of Fornaroli and Tim Cahill.
City did managed to conjure up an equaliser in controversial circumstances when Bruno Fornaroli won a converted a contentious penalty.
Perth defender Dino Djulbic did appear to make light contact with Fornaroli's foot, who went straight to ground on the moment of impact.
Perth coach Lowe was incensed and ordered to watch the second-half in the stands after appearing to abuse the referees as they walked off the field at half-time.
The moment seemed to fire up the Glory, as Keogh headed home three minutes into the second half.
The surprise selection of Dean Bouzanis ahead of Thomas Sorensen will no doubt be discussed after the 26-year-old failed to keep out Keogh's close-range header.
City coach John van 't Schip explained the decision by saying that Bouzanis had performed well both in pre-season and in the first two matches of the league.
City pushed for a second equaliser and were rewarded when Glory midfielder Brandon Wilson was disposed in midfield allowing Fornaroli and Cahill to combine to set up Fernando Brandan for his second goal of the season.
But it was Keogh who had the last word when he completed his hat-trick and secured the three points for Perth Glory.
Lowe may face action from the FFA in the coming days regarding his behaviour, however he claimed "selective amnesia" when quizzed about it after the match.