The event, which will take place at MGM Grand Garden Arena, was originally going to feature a middleweight title fight between Chris Weidman and Lyoto Machida, but Weidman withdrew earlier in the week due to a knee injury.
UFC officials confirmed the fight on Friday, following an initial report by USA Today.
Barao (32-1) is making his second defense of the undisputed bantamweight title. The Brazilian won the interim championship in July 2012 and defended it twice. He was made official champion in January, due to injuries to former titleholder Dominick Cruz. He scored a first-round TKO over Urijah Faber at UFC 169 in February.
Dillashaw (9-2) is coming off one of the most impressive wins of his career, a unanimous decision over Mike Easton at a UFC Fight Night event in January. A member of Team Alpha Male in Sacramento, Calif., Dillashaw is 5-2 in the UFC.
A former contestant on The Ultimate Fighter reality series, Dillashaw's only loss in his last five fights came via split decision to Raphael Assuncao, who was reportedly considered for the May 24 card but declined due to injury.