Costa was in a leading group of three riders alongside Dutchman Bauke Mollema and American Tejay van Garderen entering the final stages, but the pair were unable to match the Portuguese as he sprinted across the line on Friday.
"Our goal today was taking some seconds off the riders ahead of us in the overall (standings) and we didn't just do that, we also won the stage," said Costa.
"I am super happy although it was shame about the banner," added the Movistar rider, referring to a distance marker that fell onto the road just prior to the finish and briefly delayed the leaders.
"We lost around 10 seconds there which could be decisive, but the important thing is that I showed that I am in good form for (the concluding individual time-trial on) ."
Mollema edged Van Garderen to second with Frenchman Thibaut Pinot, who took the points at the summit of the HC Albula Pass, dropped as the quartet tackled the final descent.
The 206-kilometre route from Meilen to La Punt featured four rated climbs, including a brutal 30-kilometre climb of the Albula Pass that peaked at 2,315 metres just inside the final 10 kilometres.
Switzerland's Frank came in ninth 22 seconds back, having been left behind by BMC teammate Van Garderen on the climb up the Albula, but remains in yellow with Da Costa breathing down his neck ahead of Saturday's eighth stage, a hilly 180.5-kilometre route from Zernez to Bad Ragaz.
The competition wraps up on Sunday.