In numerous mythologies, solar deities tend to have double aspects, one benevolent, associated with the Sun during the day, and the other malevolent, associated with night, when the Sun is trapped in the underworld.
Avatar and nietzschefan are right. Loki could be described more as a deciever, trickster and mischief god, not as a impersonation of pure evil.
As many gods who took effigy of devil after transition from paganism to monotheistic religions, Loki was just a scapegrace who liked to make jokes of others. A rogue.
Devil is monotheistic creation.
But, while Loki shouldn't be mistaken for Odin, there was a lot of cases in many mythologies, where one god was often mixed up with other god.
And that's exactly dual nature of some gods.
Example for that is Slavic god Dazbog, Dazhbog or Dazhdbog (South-Slavic Dabog or Dajbog, Czech Dažbog, Polish Dażbóg) who could be identified with Loki in Norse mythology.
He was one of major gods in Slavic mythology and possible harbinger of later culture heroes in the folklore.
One sources say that he was solar deity. Other that he was son of Svarog (main Slavic god and actually solar deity). But, there are also many sources who claims that Dabog was main opponent of Svarog and ruller on the Earth, while Svarog was lord in the Nav (heaven).
Often he was described in folklore as a 'lame (connection with the devil and with many evil gods in other mythologies) "shepherd of wolves", an ugly demon-lord who rules the underworld and travels through world of men', deceiving them, but often help them as well.
Described as a dexterous craftsman, especially in smithery, he instructed men how to use their skills.
Although, his name was probably derived from the verb 'dat' which means 'to give', he was often mistaken for Chernobog (Black god), but also with many other gods as well.
Cthonic character of Dabog is mostly mentioned in South Slavic folklore and it fits very nicely with the solar Dazbog mentioned in Russian sources.
Other possible explanation, why some gods that were once worshiped, turned into personification of evil are monotheistic religions.
Main politheistic paganic god was threat and he was often turned into main opponent of new god.
Actually, correction. Devil got all attributes of former paramount deity.
He was cunning, deceiver, mocker, lame blacksmith and often he was hanging around with wolves. Of course, he was a bit evil.
But, he had bright moments, helping mortals and all that stuff. Thanks to his dual nature.
So, speaking of the devil.
Loki. Yes. Dabog. Also. And many other gods too.