Newcastle complete Ba swoop
The French-born 26-year-old, who has played 10 times for Senegal, is manager Alan Pardew's second signing of the summer, Newcastle's website confirmed.
Pardew told the 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."
Ba joins French international midfielder Yohan Cabaye at St James' Park following his arrival from French champions Lille last week.
Newcastle, who finished 12th last season, sold Kevin Nolan to West Ham, who will be playing in the Championship, earlier in the week.