Down by six points with 1:02 remaining in the game, Stafford took over at his own 20-yard line and engineered a six-play drive in the waning seconds.
He hooked up with Kris Durham for a 40-yard gain, then found Calvin Johnson on a 22-yard pass to the Dallas 1-yard line.
With no time-outs remaining, it appeared Stafford would spike the ball to set up a final play, but instead took the snap and lunged over the goal line for a 30-30 tie.
David Akers added the extra point and the Lions (5-3) secured a stunning win after falling to Cincinnati last week.
Stafford went 33-of-48 through the air for 488 yards with one touchdown and two interceptions while Johnson hauled down 14 passes for a career-high 329 yards and a score.
Tony Romo completed 14-of-30 passes for 206 yards and three touchdowns for the Cowboys (4-4), who had seemed on the way to a third straight win.
Swim Week Miami Beach 2014 [PHOTOS]