The tall 26-year-old defender won three Swiss league titles and two Swiss Cups with FC Basel before joining the Spanish team last year.
He also played in the Champions League with the Swiss club.
"David has a lot of experience at the top level for his age and that is very important for us at the moment," coach Marco Kurz said in a club statement on Tuesday.
"He is quick and good in one-on-one situations. I am happy that we could convince him to join us."
Kurz, who took over in mid-December, saw his team secure a goalless draw against Borussia Moenchengladbach on Saturday as the league restarted after the mid-season break.
Hoffenheim, who are in the relegation playoff spot in 16th place and one point above 17th-placed Augsburg, travel to Eintracht Frankfurt on Saturday.