Born in 1816 as the son of Matsudaira Noritada, fifth lord of the Okudono domain in Mikawa Province, he was later adopted into the hatamoto Nagai family. He served as a shogunal inspector from 1853 and, in 1854, as director-general of the Nagasaki Naval Training Institute, where he oversaw the Western-style naval education of shogunal retainers including Katsu Kaishu. As a foreign affairs magistrate from 1858 he negotiated commercial treaties with Russia, Britain, and France, and became a warship magistrate the following year. He returned to office as Kyoto city magistrate in 1862, rose to Great Inspector (o-metsuke) in 1864, and was promoted to junior councilor (wakadoshiyori) in 1867. Placed under house confinement after the Battle of Toba-Fushimi in February 1868, he crossed to Ezo that December and became magistrate of Hakodate under the Ezo Republic. Ahead of the new government's final assault in the spring of 1869, he was posted as commander of Benten Daiba as of April 7, leading roughly 300 troops including drill officers, the Hakodate Shinsengumi, and artillery. Cut off from Goryokaku after government forces occupied the town, he held out under siege until ceasing resistance and surrendering on May 15, 1869. Imprisoned after his surrender, he was pardoned in 1872 and went on to serve the Meiji government in senior posts at the Hokkaido Development Commission and the Left Chamber (Sa-in). He died in 1891 at age 76.