Maximilian Schachmann (Quick-Step Floors) won the 196-km stage from Abbiategrasso after capitalising on a breakaway to finish ahead of Ruben Plaza (Israel Cycling Academy) and Mattia Cattaneo (Androni-Sidermec-Bottecchia).
But the biggest drama was played out well behind the leaders in the main pack, with Yates (Mitchelton-Scott), who started the day with a 56-second lead over Dumoulin (Sunweb), dropped in the final few kilometres to blow the race wide open.
World time-trial champion Dumoulin followed an attack by four-times Tour de France champion Chris Froome to finish just ahead of the Team Sky rider, as Yates struggled badly for the first time at this year's Giro.
"I didn't have great legs but did the best I could. I'm still in front so it's all good," Yates said after the race.
Australia's Rohan Dennis (BMC) crossed the line just after Yates after a tough finale, limiting his losses to drop just one place to seventh in the general classification.
Dumoulin was cautiously optimistic and clearly pleased to have picked his moment so well to get within 28 seconds of rival Yates.
"I was waiting until the moment and with two kilometres to go I tried to see what was possible," he said. "Yates responded to my first attack and then Froome attacked and I tried to follow and I suddenly found (Yates) was dropped so it was nice."
Domenico Pozzovivo (Bahrain-Merida) is third in the general standings, with Froome in fourth place, three minutes 22 seconds behind Yates.
Schachmann attacked heading into the final section of the climb, finishing 10 seconds ahead of Plaza and 16 ahead of Cattaneo.
The rest of the breakaway, which escaped 16 km into the mainly flat route finished more than a minute off the pace.
"The final kilometres were really, really hard," Schachmann said. "I knew I had a good chance from the breakaway. I tried to play it safe, to not attack too early. It was really hard, we are already on stage 18 so no one has fresh legs anymore."
So, Yates' lead has been cut to 28 seconds heading into the final three days of the Giro, which includes two brutal days in the Alps.
There are four mountain passes on the route up to Bardonecchia on Friday, followed by Saturday's "queen stage" up to Cervinia before the procession to Rome on Sunday.