As you go back in history, the ultimate academic degrees were Doctors of Philosophy in the big three areas: Theology, Medicine and Law. So Jacob Bernoulli's doctorate was in Theology and his brother Johann's degree was in Medicine - but both were really mathematicians.
The Filosofie Magister (F.M. or Mag.) appears to be the first form of Ph.D. outside of the Theology/Medicine/Law. The Magister degree required a dissertation and a defense (typically in Latin until the 19th century). The degree was required for teaching at a university - and also the credential for lucrative positions teaching the scions of noblemen.
The Ph.D. began to supplant the Magister degree in the early part of the 19th century. From what I can tell, Germany led the way, and a big part of the transition was dispensing with Latin as the language for the dissertation and defense. In Sweden, the transition was around 1862-3 (although Swedish was used in dissertations earlier)