The origin of the word is a variation on the word for law (lag). In this case it means more of a common sense rule than judicial law. However, no Swede will tell you that. They will all tell you a completely different story, which I'm pretty sure they all believe to be the true origin of the word.
Here is how a Swede will explain it, but first let's break down the word. In the legend, the word lagom is the contraction of two Swedish words, laget and om. Laget means "the team" and om, in this case, means "around".
To explain the false legend of the term lagom we have to go back to the days of the Vikings. Vikings, of course, worked in teams conquering and pillaging and whatnot. There was a great deal of camaraderie and they were very careful to ensure that resources were equally distributed so that everyone could continue to contribute to the team. Weapons, food, mead, etc. were all shared in the amounts that best benefited the team. According to legend, the word lagom originated from sharing a horn of mead around the group at night. Each Viking only took as much as they needed so there would be enough to go around the team, or laget om. Eventually the two words became one word, lagom.