Gary MacKenzie fired the winner to send Dundee top of the table
Tony Bullock's save deep into injury time saw Dundee take maximum points to move clear at the top of Division One.
Dundee took the lead after 15 minutes when Colin McMenamin fired home from close range after a goalmouth scramble.
Raith levelled three minutes later when Darren Smith slotted the ball home from Gregory Tade's accurate cross.
Defender Gary MacKenzie restored Dundee's lead after being fed by Leigh Griffiths. And Bullock clawed away Allan Walker's header to seal victory.
With the game tied at 1-1, Rovers almost went ahead on the half hour mark through Johnny Russell.
Russell, on loan from Dundee United, latched onto a ball over the home defence, killed it neatly and fired a smart low shot to Bullock's near post.
But with reflexes like a ferret in a sack the Dundee keeper pushed the ball clear.
After the break Gary Harkins, on for Griffiths, who left the field to a richly deserved standing ovation, fired in a low shot but Raith keeper David McGurn saved superbly.
McGurn repeated the feat with 10 minutes remaining when he scrambled to his right to beat away Sean Higgins's low drive when the Dundee man was one on one with him.
Dundee keeper Bullock displayed his goalkeeping capabilities when he lept like a startled hare in 79 minutes to stop a thunderous Mark Ferry drive.
But he surpassed himself in stoppage-time, shortly after McMenamin had seen his header cleared off the Rovers line, when he leapt like a Romanian gymnast high to his right to claw away Walker's header.
Dundee manager Jocky Scott: "I thought that we should've created a lot more goal scoring opportunities than we did. We had plenty of the ball in and around their penalty box that I felt we could have made better use of.
"Tuesday's Co-Operative Insurance Cup tie against Rangers is a game for us now to look forward to. We've been trying to keep the players attention on the Raith game but now that's out of the way we can now enjoy it."
Raith boss John McGlynn: "We came to attack and put pressure on Dundee and I think we did that. They scored on the quarter hour mark, we went up the park four minutes later scored a good goal and got back in the game.
"They got back into it but unfortunately for us the corner kick came in and they've got some big lads. Griffiths did well at the back stick got to the byeline cut it back and they scored."
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.
Bookmark with:
What are these?