High-quality (Q) factor photonic-crystal nanocavities are currently the focus of much interest because they can strongly confine photons in a tiny space. Nanocavities with ultrahigh Q factors of up to 2,000,000 and modal volumes of a cubic wavelength have been realized. If the Q factor could be dynamically controlled within the lifetime of a photon, significant advances would be expected in areas of physics and engineering such as the slowing and/or stopping of light and quantum-information processing. For these applications, the transfer, storage and exchange of photons in nanocavity systems on such a timescale are highly desirable. Here, we present the first demonstration of dynamic control of the Q factor, by constructing a system composed of a nanocavity, a waveguide with nonlinear optical response and a photonic-crystal hetero-interface mirror. The Q factor of the nanocavity was successfully changed from ~3,000 to ~12,000 within picoseconds.