This question started when I learned that "hannya haramita" (般若波羅蜜多) comes from Sanskrit "prajñā pāramitā" (प्रज्ञापारमिता). It is not hard to see that what was /p/ in Sanskrit became /h/ in modern Japanese.
I have a guess: there was a [p]-like sound found in an early stage of Japanese (about the time when "prajñā pāramitā" was borrowed) and a sound change affected the sound turning it into modern /h/ after a while, and a new /p/ was created from some other source. Another possibility is that something in a chinese language affected it, since the Japanese terms were borrowed from China, which borrowed it from the indian sources.
Is one of these hypotheses right? If it is how was the phonological system of this early stage of Japanese and whence comes the modern phoneme /p/? What chinese language acted as an intermediate language and what was its phonological inventory (if it had any effect at all)?