Man'yōgana is the oldest known sound-based writing system used for the Japanese language. When kanji, or Chinese characters used to write Japanese, first came to Japan in around the 4th century AD through the Korean Peninsula, it was only used to write the Chinese language. Even though Chinese was not native to the Japanese people, classical Chinese writings were nonetheless studied heavily by upper-class Japanese. Some time later, although the exact time is unknown, Chinese characters, which came be known as kanji in Japan, was being used to write the Japanese language for the first time in roughly the 6th century AD, although it had a heavy Chinese influence.

Figuring out how to write the Chinese character system to correctly fit the Japanese language was quite a difficult task, since there were such big differences between Chinese and Japanese. For example, Chinese has an SVO (subject-verb-object) word order (i.e. I eat sushi), while Japanese has an SOV word order (i.e. I sushi eat). Also, while Chinese morphemes, or the smallest meaningful part of a word, are usually monosyllabic, or having just one syllable, Japanese words often were polysyllabic, or having two or more syllables. Examples of this include 山, 魚, 中, 国, 人, 多, 速 and 見. In Mandarin Chinese, the most spoken Chinese dialect in the world, these morphemes are pronounced shān, yú, zhōng, guó, rén, duō, sù and kàn in that order, all of which are just one syllable. In the native Japanese pronunciation, however, these morphemes are pronounced yama, sakana, naka, kuni, hito, oo, haya and mi(ru). What makes all this more complicated is that the last three kanji are almost never written by themselves in Japanese, if at all, since they are usually used in adjectives, verbs, and adverbs. 

Writing characters by themselves is often okay in Chinese, since Chinese is an analytic language, or a language where grammar is structured by word order, but Japanese is highly inflectional, meaning that grammar is structured by word endings. For that reason, verbs, adjectives, and adverbs almost always have at least two morphemes, the first being the derivational morpheme, or the part of the word with the root meaning, and the second and others after it are called inflectional morphemes, or parts of the word added to show a word's grammar. For example, a word that uses the character 見 is 見る mi(ru),  where the first morpheme, the kanji being 見 and its pronunciation being mi, has the root meaning "see", the second syllable ru shows that the word is a verb, making it into the word "to see". The adjective 多い oo(i) is made up of the morpheme 多 oo, meaning "many", and the morpheme い i, showing that the word is an adjective. The last examples are the two words 速い haya(i) and 速く haya(ku). While the first morpheme in both words are the two syllables 速 haya, meaning "fast",  the い i　in 速い makes the word into an adjective while the く ku in 速く hayaku turns the word into an adverb, thus the word becomes "quickly".

Due to the many differences that existed between Chinese and Japanese, the Chinese character system had to be changed to fit spoken Japanese, if it were to be understood by native Japanese speakers. The first solution the Japanese came up with was to use Chinese characters for their pronunciation and not for the meaning of the word. These were called man'yōgana, which was named after the Man'yōshu, a collection of Japanese poems that wrote Japanese using the man'yōgana. While Chinese characters used for their meaning became known as kanji, the Chinese characters being used only for pronunciation became known as man'yōgana. Man'yōgana consisted of roughly 970 Chinese characters that could be used to represent roughly the roughly 90 different morae used in the Japanese language. 

For example, while the character 山 means "mountain" in Japanese, the character itself was usually used only for Chinese loanwords, or words borrowed from the Chinese language, such as 富士山 Fuji-san, meaning "Mt. Fuji”，火山kazan, meaning "volcano”，and 山村 sanson, meaning "mountain village". Words borrowed from the Chinese language would use on'yomi (in Japanese, the on'yomi for やま is san,  zan, sen, or zen), or pronunciations borrowed from Chinese, instead of kun'yomi, or native Japanese pronunciations. During the early days of Japanese writing, native Japanese words were largely written using man'yōgana instead of kanji. For example, while the kanji for "mountain" is 山, and the kun'yomi for the word is yama, the native Japanese word would be written as 耶麻, 八馬, 矢間, 也麻, etc. to distinguish it from being a Chinese loanword, or kango.

While a modern Japanese sentence could be written like this: 私はすしを食べます Watashi-wa sushi-o tabemasu (meaning: I eat sushi), the same sentence written entirely in man'yōgana could be written as 和多氏巴寿司鳥他邊麻須, giving it a more Chinese look. Or, if someone wanted to keep all the kanji the same but replace all the modern kana, the sentence would look like this 私巴寿司鳥食邊麻須.

Although man'yōgana gave the Japanese a means to represent spoken Japanese on paper, sentences written in man'yōgana were quite difficult to read. Since Chinese characters were used for both representing the meaning of words and pronunciation, a lot of confusion could happen when a native Japanese speaker would read something written in both kanji and man'yōgana. The above examples in man'yōgana would be difficult for even a native Japanese speaker to read, especially for a modern Japanese person. On top of all that, writing everything down quickly was nearly impossible, since an entire Chinese character was needed to write down a simple Japanese syllable, some of which could have been written by up to 30 strokes of a pen.

In order to write faster, use fewer written characters, and read more easily, Japanese writers created simpler kana, or written characters to represent Japanese syllables. Buddhist monks created katakana by only using pieces of kanji so that they could write down spoken teachings more quickly. Upper-class women would use the kanji they knew and wrote cursive forms of these kanji. These became known as hiragana. While they were created separately, they later replaced man'yōgana as the main sound-based writing systems. While most sound-based writing today uses hiragana and katakana, man'yōgana is still used to write some modern Japanese words. 

These examples are called ateji. Some examples include 寿司 sushi, 亜細亜 Ajia (Asia)、亜米利加 Amerika (America)、仏蘭西 Furansu (France)、阿弗利加 Afurika (Africa)、沢山 takusan and 珈琲 kōhī (coffee)。

Sometimes, like in the case of 仏蘭西, these are the old spellings of the names of places before the Japanese decided to represent all non-Chinese loanwords with katanana. Other times, the ateji is used since the Chinese characters are more well-known in different countries than the hiragana and the katana, an example being that the Chinese can recognize 寿司, since both characters also exist in Chinese, rather than すし, since neither character exists in Chinese. While the Chinese characters for "coffee" is 咖啡, the Japanese 珈琲 is close enough that Chinese could figure it out with a little guesswork.

References

Writing systems