An all-optical transistor is a device in which a gate light pulse switches the transmission of a target light pulse with a gain above unity. The gain quantifies the change of the transmitted target photon number per incoming gate photon. We study the quantum limit of one incoming gate photon and observe a gain of 20. The gate pulse is stored as a Rydberg excitation in an ultracold gas. The transmission of the subsequent target pulse is suppressed by Rydberg blockade, which is enhanced by a Förster resonance. The detected target photons reveal in a single shot with a fidelity above 0.86 whether a Rydberg excitation was created during the gate pulse. The gain offers the possibility to distribute the transistor output to the inputs of many transistors, thus making complex computational tasks possible.