The 35-year-old will sing during the interval at the grand final on Saturday.
Eurovision bosses made clear his performance would be in a non-competitive role.
It is the first time in the history of the contest that an artist of global stature has taken to the stage to perform independently.
In a statement, Sven Stojanovic, one of show's producers said: "This is a fantastic opportunity, we are very happy and excited that Justin Timberlake will perform his new song together with his band in our show.
"It makes it extra special that the Swedish songwriters Max Martin and Shellback have co-written and co-produced the song together with Justin Timberlake."
The nine-time Grammy award-winner will perform his new song, Can't Stop the Feeling, which he wrote for the Dreamworks animation, Trolls.
BBC Radio 1 presenter Scott Mills and The Great British Bake Off's Mel Giedroyc will co-host BBC Four's live coverage of the two semi-finals on 10 and 12 May.
Graham Norton will again commentate for BBC One's live broadcast of the final from the Globe Arena.
Timberlake, who's on a promotional tour for his single, also presented the best drama series trophy at this year's Bafta TV awards, alongside actress Anna Kendrick.
The award went to BBC Two's Wolf Hall.
Timberlake's performance announcement comes after Eurovision announced Romania was being expelled from the competition for not paying their fees.
It also comes days after Eurovision bosses relaxed their flag rules, meaning the UK entry could fly a Welsh flag.
It was originally included in a list of banned flags because its red dragon was considered a political statement.
Previously only flags of contest members and UN states were allowed due to the event's non-political nature.
The UK entry features Joe Woolford from Ruthin, Denbighshire who will be performing You're Not Alone with Jake Shakeshaft from Stoke-on-Trent.
The Eurovision Song Contest is on BBC One from 2000 BST.
Justin Timberlake has said he'll be performing at this year's Eurovision Song contest in Stockholm, Sweden.