The 22-year-old midfielder, who has scored 22 goals in 125 games for Malmo since 2009, will join Hoffenheim after the German winter break in January.
The former Malmo captain, who helped them win their 17th title on Monday and has won six caps for Sweden, signed a deal to 2017.
"Hamad is a young, ambitious and still developing player who has shown his qualities in Sweden," said Hoffenheim sports director Alexander Rosen.
Hoffenheim have made a good start in the Bundesliga after narrowly avoiding relegation last season, lying ninth on 13 points from 10 matches.
(Reporting by Karolos Grohmann, editing by Ed Osmond)
