In 1872, Maxwell proposed his famous 'demon' thought experiment1. By discerning which particles in a gas are hot and which are cold, and then performing a series of reversible actions, Maxwell's demon could rearrange the particles into a manifestly lower-entropy state. This apparent violation of the second law of thermodynamics was resolved by twentieth-century theoretical work2: the entropy of the Universe is often increased while gathering information3, and there is an unavoidable entropy increase associated with the demon's memory4. The appeal of the thought experiment has led many real experiments to be framed as demon-like. However, past experiments had no intermediate information storage5, yielded only a small change in the system entropy6,7 or involved systems of four or fewer particles8-10. Here we present an experiment that captures the full essence of Maxwell's thought experiment. We start with a randomly half-filled three-dimensional optical lattice with about 60 atoms. We make the atoms sufficiently vibrationally cold so that the initial disorder is the dominant entropy. After determining where the atoms are, we execute a series of reversible operations to create a fully filled sublattice, which is a manifestly low-entropy state. Our sorting process lowers the total entropy of the system by a factor of 2.44. This highly filled ultracold array could be used as the starting point for a neutral-atom quantum computer.