The history of the language, in depth
When Japanese was written only with kanji
Before kana, writing Japanese meant forcing Chinese characters to fit. One solution was to use kanji for their sound rather than their meaning, as if they were letters: you picked a character that sounded «a» to write the syllable a, another that sounded «ka», and so on for all of them. That system is known as man'yōgana, after the great 8th-century poetry anthology in which it is used, the Man'yōshū. It worked, but it was painfully slow: every syllable cost a whole character, sometimes one with many strokes.
From there the two syllabaries emerged, along two paths. As those kanji were written quickly with a brush, their shape gradually rounded off until it became hiragana: あ comes from 安 and い from 以. The monks who annotated Buddhist texts, on the other hand, took just a piece of the character, and that is how katakana was born. Sometimes the same kanji gave both: 宇 was rounded into う and cut down into ウ, and 加 gave か and カ. That is why the two syllabaries sound the same and look so little alike.
The Heian court and literature in kana
During the Heian period, from the late 8th century to the 12th, serious writing by the men of the court was still done in Chinese. Hiragana, then called «women's writing», was used for poetry, letters and diaries. And it was in kana that the great literature of the age was written: The Tale of Genji, by Murasaki Shikibu, and The Pillow Book, by Sei Shōnagon, works by two ladies of the court around the year 1000. They are among the first great works of Japanese prose.
That literature left more than books. It established written Japanese in kana, which was later mixed with kanji to give the script used today. And it portrayed a courtly society very attentive to rank, in which the way you addressed someone said who each person was. The polite forms of modern Japanese were not born in a single moment, but that world in which manners mattered as much as content is one of their roots, and it helps explain why the language takes such care over register.
Meiji: new words for a new world
When Japan opened up to the West, in the second half of the 19th century, it lacked words for concepts that did not exist in its tradition: society, economy, philosophy, science. Instead of borrowing them as they were, the translators of the Meiji era created them by combining kanji, or gave a new meaning to old words: 社会, 経済, 哲学, 科学. Many of them later travelled to China and Korea. A good part of the abstract vocabulary studied from N3 onwards was born this way, a little over a century ago.
The other great transformation of the period was bringing the written language closer to the spoken one. Until then people wrote in a literary style that was no longer spoken, and writers and journalists pushed for writing the way people speak, with endings like だ, である or です. Added to that were the spread of schooling and the adoption of Tokyo speech as the model for standard Japanese. The Japanese learned today, in its grammar and its pronunciation, is largely the result of those decades.