Costa, riding for home-based Team Emirates, beat Katusha-Alpecin's Russian rider Ilnur Zakarin in a sprint after an 11-km climb to the finish of the 186-km mainly flat stage.
The 30-year-old former world road champion 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.
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.
Dutchman Tom Dumoulin attempted to chase them down but could not bridge the gap and had to settle for third as the two leaders fought out the stage victory on top of the Jebel Hafeet mountain.
News that makes sense
Your trusted source for staying up-to-date with the world around you. Get free daily news updates and analysis, straight to your inbox.
(Reporting by Martyn Herman; Editing by Clare Fallon)
