The striker has now put pen to paper on a three-year contract and will wear the number 19 shirt at St James' Park.
Ba, who joined West Ham from Hoffenheim in January, struck seven goals in 13 appearances for the club but activated a release clause in his contract following their relegation to the Championship.
Magpies boss Alan Pardew told the club's official website: "Demba made a great impression with West Ham last season and is a great signing for this club. He has pace, excellent technical ability, is good in the air and, it goes without saying, has the ability to consistently find the back of the net.
"Moreover he has a great passion to play for Newcastle United."