Sofien Moussa headed a late winner as Dundee manager Neil McCann had the last laugh following his simmering dispute with St Johnstone counterpart Tommy Wright.
Hearts-bound striker Steven MacLean marked his 200th game for St Johnstone with an 85th-minute strike which looked set to earn a point for the visitors at Dens Park.
But Moussa headed home three minutes later from Cammy Kerr's free-kick to hand Dundee three precious points in their quest to secure Ladbrokes Premiership safety. The Tunisian forward was also credited with the first-minute goal which sent Dundee on their way to a 2-1 victory.
The build-up to the Tayside derby had been dominated by ongoing tensions between both mangers following a disagreement in the immediate aftermath of St Johnstone's 4-0 win at Dens Park six weeks ago. There were six bookings this time but no major flashpoints.
McCann was in the stand after ultimately being handed a one-game ban for his part in a tussle with goalkeeper Zander Clark, who came into the Saints team after serving a two-match suspension.
The Dundee boss declared on the eve of the game that he had no intention of speaking to Wright after the Saints boss claimed his club had come out on the right side of the affair, and added that the Northern Irishman was "not welcome in my room either".
Wright responded with a wave as he was jeered by the home fans in the 5,592 crowd on his way to the dugout but his team found themselves behind moments later.
O'Hara hit Kevin Holt's free-kick off the inside of the post and Moussa made sure the ball went over the line, although it may have already done so.
The visitors showed a decent response as they pinned Dundee back. Joe Shaughnessy shot over after a free-kick into the box and Elliot Parish made a brilliant close-range stop after Matty Willock turned and shot.
But Dundee came back into it late in the half. Craig Wighton had an effort deflected wide after drifting inside several players on his first start of the season following a serious knee injury.
Simon Murray shot just wide after Glen Kamara's cutback and then forced a decent near-post save from Clark as Dundee kept their opponents at bay in the early stages of the second half.
The hosts had an escape in the 64th minute when Shaugnessy's acrobatic volley bounced off the bar from 12 yards out.
Murray had a free-kick pushed away by Clark but Dundee paid for sloppy defending as Holt and Kerr failed to clear and MacLean slotted home from 12 yards.
But Moussa delivered a perfect riposte as Dundee moved six points clear of bottom club Ross County.
Why are you making commenting on The Herald only available to subscribers?
It should have been a safe space for informed debate, somewhere for readers to discuss issues around the biggest stories of the day, but all too often the below the line comments on most websites have become bogged down by off-topic discussions and abuse.
heraldscotland.com is tackling this problem by allowing only subscribers to comment.
We are doing this to improve the experience for our loyal readers and we believe it will reduce the ability of trolls and troublemakers, who occasionally find their way onto our site, to abuse our journalists and readers. We also hope it will help the comments section fulfil its promise as a part of Scotland's conversation with itself.
We are lucky at The Herald. We are read by an informed, educated readership who can add their knowledge and insights to our stories.
That is invaluable.
We are making the subscriber-only change to support our valued readers, who tell us they don't want the site cluttered up with irrelevant comments, untruths and abuse.
In the past, the journalist’s job was to collect and distribute information to the audience. Technology means that readers can shape a discussion. We look forward to hearing from you on heraldscotland.com
Comments & Moderation
Readers’ comments: You are personally liable for the content of any comments you upload to this website, so please act responsibly. We do not pre-moderate or monitor readers’ comments appearing on our websites, but we do post-moderate in response to complaints we receive or otherwise when a potential problem comes to our attention. You can make a complaint by using the ‘report this post’ link . We may then apply our discretion under the user terms to amend or delete comments.
Post moderation is undertaken full-time 9am-6pm on weekdays, and on a part-time basis outwith those hours.
Read the rules here