Trafalgar led 2-0 inside 15 minutes thanks to two quickfire goals from player-boss Liam Salt and they could have added two more first-half goals but for the linesman's flag ruling them out.
Their lead was halved just before the break and Grangetown clawed their way to parity with 25 minutes left on the clock and had the momentum heading into the latter stages of the clash.
Just as the game was heading for extra-time, midfielder Lewis Taylor found a yard of space on the edge of the box following a throw-in and smashed in a first-time volley to send Traf into the semi-finals.
Boss Salt paid tribute to his depleted side for their efforts. He said: "We missed so many chances in the first half and had two goals dubiously disallowed for offside, so we should have had the game killed off by half-time.
"They were the better side in the second half and we were under the cosh a bit and had to defend well.
"We were missing Billy Logan, Sean Exley, Neil Thomas and Gary Thomas, so for us to go up there and get the win was a great effort."
Holders Traf will be hoping for a home draw in the semi-finals against Thornaby Village, Guisborough Town under-23s or The Cleveland.
Salt, whose side beat Thornaby Meerkats 7-0 in last year's final, added: "The Cleveland won it three years on the bounce before we won it last year, so they'll be a tough team.
"Hopefully we can get a home draw for the semi-final, it'll be a tough game whoever we get."