Crouch celebrates after notching Portsmouth's opener in Portugal
Peter Crouch scored twice in extra time to edge Portsmouth into the Uefa Cup group stages in dramatic fashion.
A disastrous first half for Pompey saw Douglas slam Guimaraes into the lead, before Joao Alves's 40-yard free-kick crept in to level the tie 2-2 overall.
Pompey battled back in the second half, but were unable to prevent extra time.
But they made their late superiority pay as Crouch headed in Glen Johnson's cross before Nadir Belhadj set him up to lash home to spark the celebrations.
The victory was no less than the south-coasters deserved in the end, marking a successful start to their first foray into European football in the club's history.
But they had to do it the hard way, following an appalling first half in which they surrendered their first-leg 2-0 lead far too easily.
It was a classic game of two halves in the 90 minutes, and the seeds of Pompey's woeful start were sewn in Harry Redknapp's selection - the manager's decision to go with a 5-3-2 formation exposed as naively defensive.
With Pompey looking to sit on their 2-0 first-leg lead from the first whistle, Guimaraes were able to attack with freedom and endeavour - and after centre-half Danilo had volleyed wide after David James had flapped at a corner, it was not long before the hosts opened the scoring.
The impressive Douglas was the goalscorer, making the most of Sol Campbell's failure to clear a long crossfield pass, chesting the ball down and slamming high into the net.
Pompey briefly rallied when only Flavio Meireles's diving header prevented Crouch latching onto Johnson's long ball 10 yards out, but the hosts were soon two up.
As with the opener, there was an air of charity about the second, Joao Alves planting a 40-yard free-kick all along the ground and into the corner past a static James in goal.
Once again, Johnson led the Pompey rally and the right-back brought the best out of home keeper Nilson with an excellent left-foot drive from range.
It did little to disguise a disappointing opening half, though, and Redknapp responded by pushing the full backs further on in the second half, finally prompting some attacking endeavour from the visitors.
It was a long overdue tactic, and Pompey - and Defoe in particular - thrived in the more adventurous approach, the striker twice breaking the Guimaraes backline only to squander the openings with a poor final ball, while Lassana Diarra lashed wide from range.
Suddenly it was Guimaraes sitting deep and Pompey enjoying the vast majority of possession - but unlike the hosts, Redknapp's side were unable to find any real openings, Johnson going closest in the 90 with a dipping volley inches over the bar.
And so the match went into extra-time, and with it came a couple of the best chances of the match, Fajado forcing James into a smart, low save with a driven volley for the hosts, before Defoe crashed a shot into the side netting having been set free by Arnold Mvuemba.
Minutes later, James pulled off a brilliant diving stop to keep out Joao Alves's and it appeared Pompey might live to regret their early reticence in attack.
But Crouch had other ideas as he rose at the far post brilliantly to head in Johnson's pin-point cross from the byline to put Pompey back in front in the tie, and he then lashed high into the net from 16 yards to wrap up the victory after good work by Belhadj.
It was a deserved victory in the end, but Redknapp will hope lessons will have been learned by the time they enter the group stages in late October.
Portsmouth boss Harry Redknapp: "By the time we got back to the hotel it was two in the morning and we have another big game on Sunday. Can you get another game out of those players?
"This competition takes an awful lot of your players. Unless you have got a big squad, it's a big problem."
Portsmouth striker Peter Crouch: "We let ourselves down in the first half, but we picked ourselves up and dominated the second half.
"We were a lot fitter than them, and I think that eventually made the difference in extra time.
"Glen Johnson was fantastic down the right, put in some great crosses for me and I was happy with the two goals."
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.