Ross McCormack's second-half wonder strike secured Motherwell's place in the third round of the CIS Cup.
Motherwell continued their excellent start to the season
But the SPL side were made to battle for their victory by impressive Second Division opponents Raith Rovers.
Brian McLean gave the home side a fortunate lead one minute before the interval.
Derek Carcary deservedly equalised at the start of the second half before McCormack's stunning goal, with Chris Porter adding a third in injury-time.
Motherwell manager Mark McGhee kept his promise to give an outing to his fringe players by making six changes to the side which beat Gretna, while Carcary was one of four players returning to the Raith starting line-up.
The lower league side had the better of the first half with Steven Hislop hitting the woodwork with a turn and shot from the left after just five minutes.
Porter then headed a Keith Lasley free-kick just wide of the left-hand post.
But Lasley was called into action at the opposite end of the pitch on 15 minutes when he cleared Marvin Andrews' powerful header from a Carcary corner off the line.
It took a timely tackle from Brian McLean to keep out Mark Campbell after Ryan Borris' precise crossfield pass from the left wing.
Motherwell were limited to two half-chances from McCormack, including a 22-yard shot which he sent wide of the left upright.
Hislop escaped the shackles of two markers to weave his way into an empty penalty box on 33 minutes, but the striker got the ball stuck under his feet and Reynolds was able to clear.
Motherwell had their best chance of the first half three minutes from the break when McLean's header from a Lasley corner was beaten round the post by Raith goalkeeper Chris Fahey.
The home side took the lead against the run of play with an action replay of the move on 44 minutes, McLean heading home Lasley's set piece from the left after McCormack's free-kick had been deflected out.
However, Raith emerged undaunted in the second half, Carcary breaking at pace up the right wing and playing in Borris, who shot straight at advancing goalkeeper Graeme Smith.
The visitors equalised just one minute later, though, as Carcary again breezed up the wing, bypassing marker William Kinniburgh and firing in an angled shot which beat Smith and squeezed in at the opposite post.
Motherwell were again limited to half-chances, with Fahey getting down to clutch Steven McGarry's snap shot on the hour.
But they came into the game in the final quarter and had the ball in the net on 73 minutes, only for Porter's effort to be ruled offside.
McCormack then went for the direct route and scored a minute later with an unstoppable rising drive from the edge of the area which soared into the net.
Simon Mensing hammered the crossbar soon afterwards with a header from McGarry's cross, and Porter added a third in injury-time when he netted with a diagonal drive from the right.
Motherwell: Graeme Smith, Kinniburgh, Brian McLean, Reynolds,
Corrigan, Darren Smith (McGarry 55), Lasley, Mensing, Paterson,
Porter, McCormack (Clarkson 76). Subs Not Used: Meldrum, Quinn, Fitzpatrick.
Goals: Brian McLean 45, McCormack 74, Porter 90.
Raith: Fahey, Wilson, Andrews, Campbell, Pelosi,
Borris (Sloan 67), Winter, Weir, Silvestro,
Carcary (Davidson 72), Hislop. Subs Not Used: Renton, Dingwall, Helley.
Goals: Carcary 48.
Ref: W Collum (Scotland).