From ありがたく (arigataku), the adverbial form of Old Japanese adjective ありがたし (arigatashi, modern ありがたい, arigatai). The adjective itself is a compound of 有り (ari, “stem form of verb 有る (aru), "to exist, to be"”) + 難し (katashi, “hard, difficult”, katai in modern Japanese). The katashi changes to gatashi due to rendaku (連濁).
Modern Japanese -i adjectives formerly ended in -ki for the attributive form. This medial /k/ dropped out during the Muromachi period, both for the attributive form (-ki becoming -i) and for the adverbial form (-ku becoming -u). However, the adverbial form reverted back to -ku thereafter for most words, with the -u ending persisting in certain everyday set expressions, such as arigatō, ohayō, or omedetō, and in hyper-formal speech.
/arigataku/ > /arigatau/ > /arigatoː/
Arigatashi is first attested in the oldest literature of the 8th century. Originally meant "difficult to exist, hard to be", shifting to "rare, special", and then to "welcome, thankful, nice to have" by some time in the 15th century. This sense is still in use: "Kono tenki wa arigatai ne." → "This weather sure is welcome."
Any resemblance to Portuguese obrigado (“thank you”) is purely coincidental. The Portuguese arrived in Japan in 1543, well more than a century after citations expressing gratitude are found.
Alternative forms 
ありがとう (romaji arigatō)
Usage notes 
As a fossilized adverb, this is generally followed by the verb ございます (gozaimasu, “to be; it is”, humble). May also or alternately be preceded by intensifier どうも (dōmo, “very”). Expressions of thanks are given below in rough order of casual to polite.
Coordinate terms 
- どうも (dōmo)
- ありがとう (arigatō)
- どうもありがとう (dōmo arigatō)
- ありがとうございます (arigatō gozaimasu)
- どうもありがとうございます (dōmo arigatō gozaimasu)
- 1988, 国語大辞典（新装版） (Kokugo Dai Jiten, Revised Edition) (in Japanese), Tōkyō: Shogakukan
- 1995, 大辞泉 (Daijisen) (in Japanese), Tōkyō: Shogakukan, ISBN 4-09-501211-0
- 2006, 大辞林 (Daijirin), Third Edition (in Japanese), Tōkyō: Sanseidō, ISBN 4-385-13905-9
- ^ http://kwhazit.ucoz.net/ranma/g_adj.html#hiformal
- ^ c. 759: Man'yōshū (book 17, poem #4011); online text at the University of Virginia