The Belgian attacker went from the start with Sven Erik Bystrom (UAE Team Emirates) and Jetse Bol (Burgos-BH) and took the stage wins only metres ahead of Peter Sagan (BORA-hansgrohe), the first sprinter on the line.
“When I heard we still had an advantage of 30 seconds over the peloton, I decided to stay behind Bystrom and to no longer focus on the peloton behind us," Wallays said.
"I knew he was the fastest on paper, but I also knew that the final kilometre was uphill, with gradients of 2 to 3 per cent. I decided to stay in his wheel and to start my sprint from there.
"I’ve been in similar situations before and I can keep my cool. I took a shot, but the gamble helped me to this victory, so I’m very happy I stayed in Bystrom’s wheel.
“It wasn’t easy to escape the bunch at first. My legs didn’t feel superb, but I’m a diesel and the more kilometres we covered, the better I felt. I didn't have the feeling to be the strongest in the breakaway neither, but I know I can finish strong after a long day in the breakaway, which I proved again today.
"The wind was also in our advantage, so we were able to ride at a significant high pace. Yesterday, I changed my gearing as well, enabling me to ride even faster at this course. I think we maintained an average speed of 50 km/h during the final fifteen kilometres, which is quite fast.”
Simon Yates (Mitchelton-Scott) keeps the red jersey after the 186-kilometre stage from Ejea de los Caballeros to Lleida and ahead of two days in Andorra.
He leads former Vuelta winner Alejandro Valverde (Movistar) by 25 seconds, with Enric Mas (Quick-Step Floors third at one minute 22 seconds. Miguel Angel Lopez (Astana) is fourth at one minute 36 seconds, Steven Kruijswijk (LottoNL-Jumbo) is fifth at one minute 48 seconds while Nairo Quintana is sixth at two minutes 11 seconds.
Stage 19 starts low but finishes high with a 2,025 metres Cat-1 climb on the Coll de la Rebassa closing out the 154 kilometres.
"Alejandro Valverde and Enric Mas are both very classy bike riders," Yates said. "I expect them to be very active to try and win the race.
"I think we have the strongest team now so I expect to have the most guys in the front group to help me. I’ve been living in Andorra for most of my professional career, since 2015. I know the climbs very well.
"I think the two coming stages are going to be very difficult. I’m just trying to do my own race, I think I can win and I just try to do that."