The Brazilian intended to quit F1 at the end of 2016 but returned to Williams after Valtteri Bottas moved to Mercedes following the retirement of world champion Nico Rosberg.
Massa, who has won 11 grands prix, says this time his decision is final.
The 36-year-old’s decision was influenced by the fact he wanted certainty on his future before his home grand prix next weekend.
“I agreed to return this season to help Williams when the call came,” he said.
“I have now enjoyed four great years with the team, but my career in Formula 1 will finally come to an end this season.”
He originally said he wanted to continue racing in F1 in 2018 but Williams are not yet ready to finalise their driver line-up for next year.
Massa, who achieved his biggest successes for Ferrari, added: “I take so many great memories with me as I prepare for my final two races in Brazil and Abu Dhabi, and although they will be emotional, I am looking forward to ending on a high note and preparing for a new chapter in my career.”
Williams deputy team principal Claire Williams said: “I would like to thank Felipe for all he has done for the team over the last four years. It has been an absolute pleasure to work with him.
“We are especially grateful that he agreed to postpone his retirement from F1 for a year, after Valtteri joined Mercedes, which demonstrated the depth of the relationship we built during our time together.
“We appreciate that it wasn’t an easy decision for him to return, after having such an emotional send-off at the end of last year. On behalf of [owner and team principal] Sir Frank, and all the team, we give our very best wishes to Felipe for the future.”
Williams are strongly leaning towards giving the seat alongside Canadian rookie Lance Stroll to Robert Kubica, who has not raced in F1 since suffering life-changing injuries in a horrific rally crash in February 2011.
But the team are taking their time to make their decision because of the length of Kubica’s absence.
He has only partial movement and atrophied muscles in his right arm and although the 32-year-old impressed Williams in two tests last month, there are inevitably unanswered questions as to whether he is strong enough to do a race distance at full pace on the toughest tracks.
Their reserve driver Paul Di Resta, Sauber racer Pascal Wehrlein and Red Bull reject Daniil Kvyat are also options.
Felipe Massa first joined Sauber in 2002 before moving to Ferrari in 2006 and then Williams in 2014
Massa made his debut in F1 in 2002 for the Sauber team but enjoyed his greatest period of success after joining Ferrari in 2006, initially as team-mate to Michael Schumacher in the seven-time champion’s final season for the team before his first retirement.
Massa came close to winning the world title in 2008, losing out only when Lewis Hamilton moved into the fifth place he needed to overhaul him on the last corner of the last lap of the final race of the season.
Massa won the race, the Brazilian Grand Prix, and his dignity on the podium as he battled the conflicting emotions of a home victory and losing the championship won him worldwide admiration.
He never achieved the same success again.
Ferrari were less competitive in 2009 and at the Hungarian Grand Prix that year he suffered a fractured skull when he was hit by a suspension part from another car.
He returned for the 2010 season but his new team-mate was Fernando Alonso, who proved far superior and soon came to dominate the team.
Massa stayed with Ferrari until 2013 as a support driver to Alonso before joining Williams in 2014.