Nagai was born in Myōdō District, Awa Province in what is now Tokushima Prefecture, as the son of a doctor and started studying rangaku medicine at the Dutch Medical School of Nagasaki (Igaku-Denshujo) in 1864. While in Nagasaki, he made the acquaintance of Ōkubo Toshimichi, Itō Hirobumi, and other future leaders of the Meiji government.