A characteristic signature of quark confinement is the concentration of the chromoelectric field between a static quark-antiquark pair in a flux tube. However, the structure of this flux tube, and hence of the confining force, has not been completely understood. Here we perform new lattice measurements of field distributions on smeared Monte Carlo ensembles in SU(3) gauge theory. On the basis of these simulations we demonstrate that the confining force can be understood using the analogy with the basic principles of electromagnetism as elucidated by Maxwell. We derive a chromomagnetic Lorentz force density coupling the chromoelectric field to chromomagnetic currents and integrate this force density over the flux tube interior to obtain a Maxwell-like force that squeezes the flux tube in the transverse direction. We show that the strength of this transverse confining force is equal to the value of the string tension calculated numerically from the chromoelectric field on the midplane between the quarks, verifying the consistency of these two complementary pictures of confinement.