Nagai was born in the Myōdō District, Awa Province in what is now the 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.
Nagai continued his studies at Tokyo Imperial University and became the first doctor of pharmacy in Japan. He was sent under government sponsorship to Prussia in 1871 to study at the University of Berlin. He was the only civilian in a group of military students sent to study in Great Britain and France, and he traveled by way of the United States and Great Britain. While in Berlin, he resided at the home of Japanese diplomat Aoki Shūzō. He was influenced by the lectures of von Hofmann, and received a doctorate with a study on eugenol while working as an assistant at von Hofmann's laboratory. He decided to take up organic chemistry in 1873.
Nagai returned to Japan in 1883 to take up a position at the Tokyo Imperial University, and became Professor of Chemistry and Pharmacy there in 1893. His research centered on the chemical analysis of various Japanese and Chinese traditional herbal medicines.
While in Germany, Nagai married Therese Schumacher, the daughter of a wealthy lumber and mining magnate. On their return to Japan, she became a professor of German language at Japan Women's University, and was active in introducing German foods and culture to Japan. In 1923, Nagai and his wife hosted Albert Einstein and his wife during their visit to Japan.