Magnetic fields generated by human and animal organs, such as the heart, brain and nervous system carry information useful for biological and medical purposes. These magnetic fields are most commonly detected using cryogenically-cooled superconducting magnetometers. Here we present the first detection of action potentials from an animal nerve using an optical atomic magnetometer. Using an optimal design we are able to achieve the sensitivity dominated by the quantum shot noise of light and quantum projection noise of atomic spins. Such sensitivity allows us to measure the nerve impulse with a miniature room-temperature sensor which is a critical advantage for biomedical applications. Positioning the sensor at a distance of a few millimeters from the nerve, corresponding to the distance between the skin and nerves in biological studies, we detect the magnetic field generated by an action potential of a frog sciatic nerve. From the magnetic field measurements we determine the activity of the nerve and the temporal shape of the nerve impulse. This work opens new ways towards implementing optical magnetometers as practical devices for medical diagnostics.