The Scotland Under-21 striker, playing for the first time since being disciplined following his arrest for an alleged assault, tapped in only two minutes after his 76th-minute introduction as a late substitute.
It was the third time United, who were reduced to 10 men three minutes from time when Danny Swanson saw red for a wild lunge on Gavin Swankie, had taken the lead in a see-saw match.
Danny Cadamarteri gave the visitors the lead from the spot before Filipe Morais sent the teams in level at the break with the aid of a deflection off Darren Dods.
Andy Webster then restored United's lead shortly after the interval, only for home substitute Martin Hardie to restore parity with a free-kick with his first touch of the ball.
Goodwillie was the match-winner, however, as he popped up to knock home after Damian Casalinuovo's effort had rebounded off the post.
Saints were the first to threaten when Collin Samuel's cross from the right was volleyed in by Kenny Deuchar but goalkeeper Nicky Weaver did magnificently well to block with his feet after Filipe Morais had deflected the striker's effort six yards out.
Despite the home team's greater threat going forward it was United who broke the deadlock in controversial fashion in the 34th minute.
Dave Mackay was adjudged by referee Dougie McDonald to have handled Lee Wilkie's header as it headed towards goal and Cadamarteri blasted in from the spot.
However, within three minutes Saints were level.
Morais latched on to a Deuchar knock down in the box and his resulting shot sneaked into the net via Weaver's attempted block and an apparent deflection off defender Darren Dods.
Murray Davidson should really have given Saints the lead two minutes from the break as he raced on to Samuel's flick but he delayed too long and Paul Dixon made a magnificent last-ditch tackle.
Within two minutes of the restart United restored their lead. A long throw from the left arced over the head of Wilkie and was allowed to bounce on the edge of the six-yard box where Andy Webster was first to react to rattle his shot into the net.
Saints worked their way back into proceedings and Weaver had to dive full length to his left to tip away Morais' long-range effort in the 63rd minute.
Nine minutes later they were level as Saints manager Derek McInnes sent on substitute Martin Hardie in time to take a free-kick, and he proved his set-piece ability by firing the ball into Weaver's bottom left-hand corner.
The see-saw match was still not finished, however, and only four minutes later United were back in front.
Casalinuovo found space in the box and when his shot was touched onto the post by home goalkeeper Alan Main, substitute Goodwillie followed into tap in from a yard.
United were forced to play the last three minutes of regulation time with only 10 men after Swanson's dismissal and then Goodwillie was denied a second by Swankie's goal-line clearance.