I'm not referring to the real animals that spawned the legend, such as the narwhal and rhinoceros; I'm trying to track the introduction of the fantastical elements. Do we know when, and by whom, these facts were invented?
The Unicorn Legend sort of spawned in Greece, except it wasn't a legend, they actually believed it was a real animal. Which is why you don't see Unicorns in Greek Mythology, but you DO do see them in their writings on natural history. Ctesias wrote that it lived in India (As you know there are a couple of animals that would have lead to this belief). Some Scholars believe that the idea of the Unicorn came from old cave paintings of goats or bulls. Which from a side view might appear to only have one horn, and could look similar to a horse.
Now at the time that the Greeks thought that the Unicorn existed, they didn't know too much about India other than it was sort of mystical and mysterious, so naturally that's where a magical horned horse would live. It also helped that Ctesias happened to be living in India at the time.
To further reinforce this point, in a few places in the bible there are references to Unicorns. [Num 23:22 & 24:8], [Deu 33:17], [Isa 34:8 see also Psa. 92:10 & Psa 22:21]. The New Testament was written in Greek, so it makes sense that they would compare the mythical Jesus Christ or other biblical figures to a strong mythical creature they also believed existed. Though it may just be a misinterpretation of the Hebrew word re'em when they were writing the bible.
To answer the magical/mythological elements, these were all just how the Greek Ctesias described them, it was fantastical lies or a misunderstanding of a real animal. Which was perpetuated by Christians in the middle ages reading about Unicorns in the bible.
If you want a really cool book about the subject check out Chris Lavers "The Natural History of Unicorns" Harper Perennial; 1 edition (July 20, 2010)