Costa (UAE Team Emirates) beat Katusha-Alpecin's Ilnur Zakarin in a sprint after an 11km climb to the finish of the 186km stage from Hazza Bin Zayed Stadium to Jebel Hafeet.
Tom Dumoulin (Sunweb) attempted to chase the pair but could not bridge the gap and had to settle for third as the two leaders fought out the stage victory on the climb to the finish.
The 30-year-old former world road champion Costa now leads Zakarin by four seconds going into the final day around the local Formula One circuit and, barring a crash, looks set to claim victory.
“It wasn’t easy with so many good riders and the stage was very complicated because there was a lot of wind and a couple of attempts by different teams to split the race,” Costa said.
“Movistar started the climb very fast, while I was forty positions behind and had to ride back up through the field, which cost me a lot of effort.
“When I attacked it was just to see how it went and who came with me but my legs responded well. Zakarin came with me, then at the finish I drew on some of the energy I had managed to save in the last couple of kilometres.
“I worked well with Zakarin, also because we knew that the guys behind were very strong. The cooperation between us was absolutely key.”
A five-man breakaway built up a lead of five minutes through the desert but was reeled in 15km from the end when Costa and Zakarin attacked the peloton and forged ahead on the Queen Stage of the new minted WorldTour stage race.
Pre-race favourites Alberto Contador (Trek-Segafredo), Nairo Quintana (Movistar), Vincenzo Nibali (Bahrain-Merida) and Fabio Aru (Astana) did not feature.