Giroud delivered left-foot, right-foot and headed finishes for the perfect treble – and then whipped a spot-kick into the top corner for good measure.
Chelsea will host Krasnodar at Stamford Bridge next week, but sealed top spot with their win in Spain, and a potentially easier tie in the last-16.
Gudelj forced a good save from the ever-impressive Mendy to open the second half.
But just as with the first period, it was to be the visitors who forced a breakthrough.
And once again the imperious Giroud delivered the telling blow, this time dinking home with his right foot for a finish that even bettered his opener.
Still not sated by his first two goals, Giroud then ensured he would head home with the match ball – nodding in from replacement N’Golo Kante’s accurate cross.
Giroud then found time to win and convert a late penalty, to add even further gloss to his night.