A liquid ejector includes a liquid ejection head, a discharge path, a cap, a pump, a first tank, a second tank, a first valve, and a second valve. The liquid ejection head ejects liquid through a nozzle. The cap covers the nozzle. The pump sucks the liquid from the liquid ejection head through the cap and the nozzle and conveys the liquid to a downstream end of the discharge path. The first tank communicates with the outside air, and temporarily stores the liquid in the discharge path. The second tank is detachably attached to the liquid ejector and is connected to the downstream end of the discharge path. The first valve switches the state of the first tank between open to and cut off from the outside air. The second valve switches the state of the first tank between connection to and cut off from the second tank.