Matthew Pennington looked to have sealed a memorable win for Steve Cotterill's side against their Championship opponents with nine minutes to go.
But the highly-rated Stewart levelled in the second minute of added time.
And then, with deflated Shrewsbury settling for a replay at the Stadium of Light, they were undone again as O'Nien pounced two minutes later to send the Black Cats through.
Shrewsbury started brightly and Luke Leahy rattled the bar in the sixth minute.
At the other end Trai Hume went close to his first goal for Sunderland as his effort was whiskers away, while Patrick Roberts pulled a shot wide late in the first half.
After the break Shrews goalkeeper Marko Marosi did well to deny in-form Stewart before Amad Diallo became the latest Sunderland man to fluff his lines.
And they were made to pay when defender Pennington headed home late on.
But Stewart levelled with his 10th goal in 12 games this term as he nodded in Jack Clarke's corner.
And O'Nien found the bottom corner right at the end to complete a remarkable turnaround.