Old English þancian, þoncian "to give thanks, thank, to recompense, to reward," from Proto-Germanic *thankōjanan (source also of Old Saxon thancon, Old Norse þakka, Danish takke, Old Frisian thankia, Old High German danchon, Middle Dutch, Dutch, German danken "to thank"), from *thankoz "thought; gratitude," from PIE root *tong- "to think, feel."
It is related phonetically to think as song is to sing; for sense evolution, compare Old High German minna "loving memory," originally "memory." Also compare related Old English noun þanc, þonc, originally "thought," but also "good thoughts, gratitude." In ironical use, "to blame," from 1550s. To thank (someone) for nothing is recorded from 1703. Related: Thanked; thanking.