The announcement was made Friday by show producers Michael De Luca and Jennifer Todd.
The gala honoring excellence in film is to be hosted by Jimmy Kimmel. It will air live on ABC.
"We're thrilled to welcome these world-class artists to the Oscars. These performances will not only celebrate the five extraordinary nominated original songs, but also the integral part music plays in movies," De Luca and Todd said in a joint statmenet.
Auli'i Cravalho will join Miranda to perform "How Far I'll Go" from Moana; Sting will perform "The Empty Chair" from Jim: The James Foley Story; Timberlake will perform "Can't Stop The Feeling" from Trolls; and Legend will perform both "Audition [The Fools Who Dream]" and "City of Stars" from La La Land.