Finnish driver Valtteri Bottas will replace retired Formula One world champion Nico Rosberg at Mercedes this season, with Felipe Massa agreeing a one-year contract at Williams.
Brazilian Massa, who retired at the end of last season, takes over the seat vacated by Bottas.
“Williams is pleased to confirm that Felipe Massa has agreed to re-join Williams on a one-year deal, coming out of retirement to replace Valtteri Bottas who the team has released to join Mercedes for the 2017 season,” Williams said in a statement.
There was no immediate word from Mercedes.
Bottas, 27, will partner Britain’s triple world champion Lewis Hamilton at dominant Mercedes, winners of the last three drivers and constructors’ titles and favourites again this year.
The Finn has yet to win a grand prix in four seasons at Williams, making nine podium appearances, but he can now expect to end that wait and step up as a genuine contender for the title.
The 35-year-old Massa, a former race winner with Ferrari and 2008 world championship runner-up, will partner 18-year-old Canadian rookie Lance Stroll.
“I always intended to race somewhere in 2017, but Williams is a team close to my heart and I have respect for everything it is trying to achieve,” said the Brazilian, who made a tearful farewell to his home crowd last November.
“Valtteri has a great opportunity, given the turn of events over the winter, and I wish him all the best at Mercedes.
“When I was offered the chance to help Williams with their 2017 Formula One campaign, it felt like the right thing to do. I certainly have not lost any of my enthusiasm for racing and I’m extremely motivated to be coming back to drive the FW40.”
Williams deputy principal Claire Williams had said the team would not stand in Bottas’s way, providing they could secure a suitable replacement.
Sauber earlier set the merry-go-round in motion by announcing that German driver Pascal Wehrlein, who was the Mercedes reserve and Bottas’s main rival to replace Rosberg, would race for them this year.
Wehrlein, 22, drove for struggling Manor as a rookie last year but Mercedes felt they needed a more experienced replacement.