Devoid of a lead-out train, Greipel showed a wicked turn of speed to come from far back and overturn Degenkolb’s lead in the closing metres, with Groenewegen joining the pair in a finish separated by the smallest of margins.
It is Greipel’s second win of the season – he won his opening race of the campaign at Challenge Majorca – and his fourth in the history of the race.
Primož Roglič, who took the race lead after stage three’s time trial, finished comfortably in the bunch to ensure that he goes into Sunday’s final stage as leader.
Ireland’s Ryan Mullen (Cannondale-Drapac) helped to initiate the breakaway after just six kilometres. He was joined by Taco van der Hoorn (Roompot-Nederlandse Loterij), former One Pro Cycling rider Dion Smith (Wanty-Groupe Gobert) and João Matias (LA Alumínios-Metalusa).
They were allowed to build a lead of over 6 minutes after 55km, and even though they lost Matias with 30km left, the remaining three riders started to believe they had a chance of prevailing when 2:40 was their advantage with 22km until the finish.
10kms later and they still had 80 seconds, with a peloton headed by Quick-Step Floors furiously doing the pacing to reign the trio in.
They were eventually caught with just over two kilomotres to go by a peloton that was spearheaded by Degenkolb’s Trek-Segafredo.
Quick-Step and Trek swamped the front of the race in the final kilometre and Jasper Stuyven led Degenkolb expertly into the final 500 metres, just as Quick-Step did for stage one winner Fernando Gaviria.
Greipel started his sprint from deep, but it appeared to help him as he was allowed to get between Gaviria’s and Degenkolb slipstream before forcing himself beyond the former and in line with his German compatriot.
Arnaud Démare (FDJ) and Groenewegen (LottoNL-Jumbo) also both came from far out, but it was Groenewegen who edged himself parallel with the two Germans, requiring the race jury to turn to a photo finish that determined Greipel as the winner.
Roglič didn’t lose any time and remains in the leader’s jersey by 22 seconds going into Sunday’s final stage, an 2.8km uphill finish to Malhão.
Volta ao Algarve 2017, stage four: Almodôvar to Tavira, 203.4km
1. André Greipel (Ger) Lotto-Soudal in 4-57-51
2. John Degenkolb (Ger) Trek-Segafredo
3. Dylan Groenewegen (Ned) LottoNL-Jumbo
4. Arnaud Démare (Fra) FDJ
5. Jasper Steven (Bel) Trek-Segafredo
6. Andrea Pasqualon (Wanty-Groupe Robert)
7. Fernando Gaviria (Col) Quick-Step Floors
8. Nacer Bouhanni (Fra) Cofidis
9. Michael Schwarzmann (Ger) Bora-Hansgrohe
10. Edvald Boasson Hagen (Nor) Dimension Data all at same time
General classification after stage four
1. Primoz Roglic (Slo) Team LottoNL-Jumbo, in 14-34-20
2. Michael Kwiatkowski (Pol) Team Sky, at 22 secs
3. Jonathan Castroviejo (Esp) Movistar, at 36 secs
4. Tony Gallopin (Fra) Lotto-Soudal, at 55 secs
5. Luis Leon Sanchez (Esp) Astana, at 59 secs
6. Dan Martin (Irl) Quick-Step Floors, at 1-31
7. Tony Martin (Ger) Katusha-Alpecin, at 1-40
8. Tiesj Benoot (Bel) Lotto-Soudal, at 1-49
9. Amaro Manuel Antunes (Por) W52-FC Porto-Porto Canal, at 1-54
10. Rinaldo Nocentini (Ita) Sporting Clube de Portuga/Tavira, 1-56