The Blades were crusing at 2-0, thanks to goals from Billy Sharp and Chris Basham, before Preston snatched two goals in three minutes to make it 2-2.
But up popped McGoldrick to net an 87th minute winner and secure another three points for the Blades.
McGoldrick came closest to breaking the deadlock, but his header was blocked in the 26th minute.
But the Blades were in front before half-time, and again McGoldrick proved key. The striker's effort was deflected across goal and fell invitingly for the unmarked Billy Sharp to blast the ball into an empty net.
And McGoldrick came close to a second goal, but failed to get his header on target after a perfect back-post cross from Enda Stevens.
Chris Basham netted from a glancing header on 51 minutes, converting Ollie Norwood's free-kick, earned after a silly challenge by Paul Huntington on McGoldrick.
And the latter could have made it 3-0, seconds later, but dragged his shot wide of Chris Maxwell's goal.
Blades goalkeeper Dean Henderson had to be alert to deny Tom Clarke's back-post header, as the visitors looked for a way back into the game.
Preston made it 2-1 with 10 minutes to go, Darnell Fisher's cross knocked home by Callum Robinson.
And two minutes they were level, substitute Daniel Johnson's deflected shot creeping in.
Leon Clarke was thrown into action, as United went in search of a winner, and McGoldrick pounced to score in the 87th minute.
“I’m delighted and proud with the way we set up,” said Blades boss Chris Wilder.
“It was never dull, but the players showed tremendous character to get themselves back up off the canvas.
“Even the most ardent of Preston North End fans would say that we did more than enough in the first 60 minutes to be comfortable and out of sight. But we didn’t and respect to them as they came back and changed their shape around a bit.
“I’m delighted to get the right result, which in my opinion is a home win. We went back to the team that’s done ever so well recently and I thought we were outstanding in the first half.
“I’m delighted we got our noses in front and the swagger about us was good to see.
“I’m a pessimistic football manager and I know anything can go wrong at 2-0.
“We made a positive substitution at 2-2 and we’ve managed to win it. Not how we thought at half past four, but it would have been a travesty if we hadn’t.”