Williams and Fonotia swap clubs.
The 27-year-old won his 50th Test cap when Wales were beaten by New Zealand at the weekend.
"I hope it goes without saying that this has not been an easy decision for me but ultimately I feel it is a move that is the right option for me at this time in my career," Williams said in a statement released by the Ospreys.
Williams made his Scarlets debut in 2010 before making a first Wales appearance the following year and going on to be part of two successive World Cup campaigns.
"Negotiations to retain Scott have been ongoing for some months, but today we can confirm he will be leaving us at the end of the season," said Scarlets general manager Jon Daniels.
"Sometimes, despite everyone's best efforts, a player decides the next chapter of his rugby career should be at another club."
Ospreys Samoa international centre Kieron Fonotia will head in the opposite direction next season when he links up with the Scarlets.
* Meanwhile Scarlets revealed that Ospreys centre Kieron Fonotia will join the them ahead of the 2018-19 season.
New Zealand-born Fonotia joined the Ospreys from the Crusaders in 2016, following a successful season with the Super Rugby side.
Fonotia was a regular feature in a star-studded Crusaders backline, which included Scarlets fullback Johnny Mcnicholl, since making his Super Rugby debut at the start of the 2014 season, scoring a try with his first touch as a 70th minute replacement in a 14-13 win over Stormers.
At the end of that season he started the Super Rugby Final on the wing as Crusaders were defeated 33-32 by the Waratahs.
Since arriving in Wales the 28-year-old has made 29 appearances for the Welsh region scoring six tries. He scored his first try for the region against Grenoble Rugby in last season's Challenge Cup.
Fonotia made his international debut, for Samoa, against his native New Zealand this year, before facing Wales at Apia Park a week later.
Commenting on the signing of Fonotia, who can play in the midfield and on the wing, head coach Wayne Pivac said: "We are delighted to be in a position to confirm that Kieron Fonotia will be joining us at Parc y Scarlets next season.
"He'll bring a physical edge along with attacking flair and ability to the squad and the style of play he's used to playing back in New Zealand with the Crusaders will set him in good stead and should make for an easy transition the the Scarlets style of play."
Kieron Fonotia said; "I'm very excited to be joining the Scarlets next season and playing again with a few familiar faces. They've had a very successful couple of years playing some good rugby and hopefully I can help develop that further.
"However, my priority now and for the remainder of the season, is to help improve the league position at the Ospreys and make sure the Ospreys climb up the conference and finish the season successfully."