The complete form of this special version of "Thank you" is:

ご馳走様でした
gochisôsama deshita

Go means "honorable." Chisô means "feast" or "entertainment." Sama originally meant "lord," and is a way of turning a noun into a personification. Deshita means "was" or "were."

So the real meaning of gochisôsama deshita is "you were an honorable host."

There are several ways to say this. In informal situations, people like to say gochisôsan, essentially a shortened version of the full phrase with the honorific sama changed to a more friendly san. The Kansai dialect spoken by natives of Kyoto and Osaka likes to replace "sa" and "da" sounds with "ha" sounds, and uses gochisôhan.

Also, the phrase isn't restricted to right after the meal. If someone takes you out to dinner, and you see them the next day, you can say Kinô wa gochisôsama deshita, "Thank you for being such an honorable host yesterday." The same goes for today, last week, or whenever. It makes a good icebreaker in conversation if you know how to use it properly.