Quick-fire goals from Jake Cooper and Lee Gregory after the break gave Millwall hope of a second league win of the season, after Billy Sharp had opened the scoring for the visitors.
But McGoldrick struck twice, the first coming from the penalty spot 10 minutes from time before tapping home from close range as the Blades picked up their sixth Championship win of the season despite Sharp missing a penalty.
"It shouldn't have been a nail-biter," said Blades boss Chris Wilder.
"We had to be right at it. For five minutes we weren't and we got punished. But for the majority of time we were and we all played our part in what I believe was a deserved victory.
"If we'd have walked away with two each I would have been delighted with the way we played. Credit to them.
"The momentum is gone, the place is rocking and it's changed from a comfortable afternoon to one that's going to be difficult.
"I'm just glad we don't have to come here because it is such a difficult place to play. No doubt they'll get a result and they'll be up and running.
"They're a tough team no matter how you look at it. They've got too many good players, too many honest professionals that want to run around and get a result.
"Millwall will find a way to win, without a shadow of a doubt.
"We're delighted with 19 points after 10 games but that can quickly change if things aren't right."
Millwall, meanwhile, are now without a win in seven and sit in the relegation zone, with pressure mounting after their underwhelming start to the campaign.
A lively opening to the game saw the hosts have a goal disallowed but Sheffield United boasted a golden chance when a cross was adjudged to have been handled by Shaun Williams in the penalty area.
Sharp stepped up from 12 yards but Ben Amos' superb save saw the ball tipped onto the bar, a moment that sparked the hosts into life.
Sharp redeemed himself just five minutes before the break, opening the scoring with a glancing header for his fifth league goal of the season.
Millwall fans voiced their disappointment at the break but the second half was a different matter, Cooper heading home from a corner just two minutes after the restart to level up the contest.
And just three minutes later the Lions were ahead for the first time when Ryan Leonard lobbed a ball behind the Blades backline for Gregory to run onto, taking a touch to then poke from the left side of the six-yard box into the far corner.
Spurred on by the vocal support, Millwall smothered United but two quick Blades chances, one thwarted by a superb Cooper tackle and another saved excellently by Amos, slightly slowed the momentum.
And the hard work was undone when Aiden O'Brien clattered into Mark Duffy from behind as United were awarded their second penalty of the game.
With Sharp removed from spot-kick duties, McGoldrick calmly stepped up and sent Amos the wrong way to level up at 2-2.
But United were not done there, with just two minutes left on the clock when McGoldrick stabbed home from close range, benefiting from sloppy defending to tap in from just three yards.
Millwall pushed in the latter stages but could not do enough to equalise for a second time in the game, still holding just one win from the Championship season.