Third Division Dumbarton pulled off a surprise win at Starks' Park to set up a glamorous Scottish Cup third round tie at Celtic Park.
Dumbarton's John Gemmell saw his 50th minute penalty saved by Chris Fahey after Chris Boyle had been tripped.
But the striker made amends a minute later when he crashed home a shot from 12 yards off the under side of the bar.
Rovers were reduced to 10 men when Brian Fairbairn was dismissed for a kick at Gemmell.
Raith Rovers: Fahey, Bonar, Campbell, Andrews, Fotheringham, Fairbairn, Ian Davidson, Silvestro, Curry (One 58), McManus, Thorarinson. Subs Not Used: Lumsden, Bannermen, Kilgannon, Currie.
Sent Off: Fairbairn (65). Booked: Bonar, Campbell.
Dumbarton: Grindlay, Geggan, Canning, Craig, Brittain, Borris (Hamilton 79), Gentile, Winter, Bagan, Boyle, Gemmell (McQuilken 89). Subs Not Used: Dillon, McNaught, Shaw.
Goal: Gemmell 51.
Att: 1,616
Ref: C Hardie