The first phonetic spelling of Japanese was using kanji. This system was called man'yōgana, named after the Man'yōshū, an anthology of poems from the Nara period written in this manner. Hiragana and katakana developed as abbreviated forms of these kanji.
Although spelling wasn't entirely consistent, and multiple characters were used for individual sounds, Japanese spelling reflected the phonology of the time fairly well, and by looking at changes in spelling over time, we can observe sound changes such as the merger of kō-otsu.
At this point, I'd like to quote some passages from Frellesvig's A History of the Japanese Language (2010). Although I've tried to pare the quotes down to a minimum, they're still quite long, so I've bolded the key sections in case you'd like to skim.
The Japanese alphabet was, in part, standardized by the Iroha-uta. From page 165:
[T]he establishment and awareness of distinct orthographic categories is evident from three mnemonic word lists or poems from the first half of the Heian period in which each distinct letter category occurs only once: the Ame-tsuchi no kotoba (or Ame-tsuchi no uta), Taini-uta, and Iroha-uta … These lists/poems functioned as a kind of ABC to remember the distinct letter categories …
The three lists concur in not having distinct letters or representation for sei'on and daku'on. Chronologically, they all reflect a stage of the language after the merger of the kō-otsu distinctions (as there is no representation of these distinctions), but before the merger of non-initial /-p-/ with /-w-/ (950-1000, …
And from page 168:
It is difficult to exaggerate the importance of the establishment and dissemination of the Iroha-uta. It is a defining event in the history of Japanese script and writing, and more generally in Japanese culture, linguistic and otherwise, … The Iroha-uta finally defined the forty-seven kana letter categories which, with the sole addition of ん/ン for the moraic nasal, still are in use today, enshrined the principle of not having separate letters for sei'on and daku'on, and fixed the sequence of letters in a list. …
The Iroha continued to function as the Japanese alphabet, as a linguistic and meta-linguistic organizing principle until it eventually was replaced by the gojūonzu in the middle of the Meiji period…
However, Japanese sounds continued to change after the kana became well-established, and spelling didn't always change with it. From page 173:
[F]or the kana categories おをほ, いゐひ, えゑへ, うふ, わは, the mapping between sound and writing became much less straightforward than it had been …, and as may be expected, this led to efforts to regularize the use of these kana letters. Rather than reforming the inventory and use of kana letters along simple phonographic lines, … an etymological spelling principle gained ground from around the beginning of the thirteenth century, eventually resulting in the so-called rekishi-teki kana-zukai (歴史的仮名遣い) ‘historical kana-usage, historical spelling’ … The simple principle is that any word is to be spelled the way it was, or would have been, spelled within the kana categories of the Iroha, before the sound changes outlined [earlier in this chapter] took place. Thus kai ‘shellfish’ (< OJ kapi) is spelled かひ, ai ‘indigo’ (< awi) is あゐ, and kai ‘rudder’ (< ka.i) is かい. …
On pages 174-175, Frellesvig goes into more detail about who established the spelling principles and when. This section, I think, answers the core of your question:
The etymological spelling principle was first explicitly proposed by the poet and scholar Fujiwara no Teika (1162-1241) as part of his recommendations of the spelling of individual words … His primary concern was the production of faithful editions of earlier texts, preserving their original shape, and he based his spelling proposals on inspection of earlier manuscripts and text versions in order to establish original, ‘correct’ spellings. It seems there was some consensus about the spelling of individual words before Teika, at least to some extent on an etymological basis, … but it was Teika who explicitly established the etymological spelling principle which, together with his specific spellings of individual words, came to be known as Teika kana-zukai … and soon acquired the status of a spelling norm, … Thus, from Kamakura to early Edo most literary writing was spelling according to the Teika kana-zukai. …
There are inevitably not a few mistakes in Teika's etymological spellings … first of all because the copies of texts he had access to and worked from already contained errors … Therefore later scholars elaborated on and amplified Teika's work. The Kanamoji-zukai (completed after 1363) by the monk Gyōa … is the first large-scale application of Teika's principles. It lists spellings for more than a thousand words and for a long time served as the major normative spelling reference. … Mention must also be made of the kokugaku scholar Keichū (1640-1701) who provided the basis for the rekishi-teki kana-zukai in use today. In his Waji shōranshō (1695) he set the etymological spelling principle on a firm philological footing with systematic citation for specific spellings of sources which even by today's standards are mostly reliable.
And this system lasted for quite a long time, with some small changes. Modern sound changes were largely ignored, and so over time the system became further and further divorced from modern pronunciation. From page 173:
At the beginning of the NJ [Modern Japanese] period further sound changes took place which resulted in phonographic equivalence before the high vowels /i, u/ … rendering the kana pairs じ/ぢ and ず/づ phonographically equivalent. By then the etymological principle had long been established and so the principle for which kana to use was fairly clear, although usages which can be thought of as ‘spelling mistakes’ (for example writing mizu ‘water’ < midu as みず rather than the etymologically correct みづ) are frequent in Edo period NJ texts.
Although historical kana spelling started out largely ignoring the voiced-voiceless distinction, the voicing marks were occasionally used when it was necessary to indicate pronunciation more precisely, and eventually, the voicing marks became common. From pages 163-164:
The earliest attested use of diacritics to mark sei or daku on man'yōgana is from the late ninth century, and on kana from the eleventh century … [S]ei-daku … remained un-noted in general writing in the [Early Middle Japanese] period. … [I]t was not until … the beginning of the Edo period … that the dakuten we know today became established and widespread in general writing.
The dakuten was originally a voicing mark, distinguishing the voiced /g z d b/ from the voiceless /k s t p/ respectively. However, due to the sound changes in the /p/ row, the phrase "voicing mark" is no longer entirely accurate—the /p/ row is now the /h/ row, and /b/ is of course not a voiced version of /h/!
Since /p/ was retained in some contexts, this row now represented three phonemes, and the handakuten developed as a way to distinguish /p/ from the other two. From page 165:
However, towards the end of the [Late Middle Japanese] period Portuguese Jesuit missionaries instituted the use of a circle on the top right corner of a kana … in order to write unambiguously pV, e.g. は (fa/ha), ぱ (pa). This was first used in Rakuyōshū, a kanji dictionary published … in 1598. Since then this practice gradually spread and is, of course, today a fully integrated feature of Japanese writing.
And less than a hundred years ago, the system was finally replaced. From page 173:
The rekishi-teki kana-zukai was only abolished as the norm with the orthographic reforms in 1946 when the gendai kana-zukai … was adopted, in which the etymological principle largely has been abandoned, with a few well-known exceptions.
So as you can see, the development of Japanese spelling over more than a millennium was rather complicated. It started out as a relatively faithful rendition of speech, but pronunciation changed over time, and historical or etymological spellings took hold relatively early on. There was some variation in convention and there were some errors made, and there were several revisions of the system, and finally the addition of the dakuten and handakuten diacritics; but ultimately it was replaced in 1946 with modern spelling conventions, which were then revised again in 1986.