The challenge of controlling magnetism using electric fields raises fundamental questions and addresses technological needs such as low-dissipation magnetic memory. The recently reported two-dimensional (2D) magnets provide a new system for studying this problem owing to their unique magnetic properties. For instance, bilayer chromium triiodide (CrI3) behaves as a layered antiferromagnet with a magnetic field-driven metamagnetic transition. Here, we demonstrate electrostatic gate control of magnetism in CrI3 bilayers, probed by magneto-optical Kerr effect (MOKE) microscopy. At fixed magnetic fields near the metamagnetic transition, we realize voltage-controlled switching between antiferromagnetic and ferromagnetic states. At zero magnetic field, we demonstrate a time-reversal pair of layered antiferromagnetic states which exhibit spin-layer locking, leading to a remarkable linear dependence of their MOKE signals on gate voltage with opposite slopes. Our results pave the way for exploring new magnetoelectric phenomena and van der Waals spintronics based on 2D materials.