Merging neutron stars offer an exquisite laboratory for simultaneously studying strong-field gravity and matter in extreme environments. We establish the physical association of an electromagnetic counterpart EM170817 to gravitational waves (GW170817) detected from merging neutron stars. By synthesizing a panchromatic dataset, we demonstrate that merging neutron stars are a long-sought production site forging heavy elements by r-process nucleosynthesis. The weak gamma-rays seen in EM170817 are dissimilar to classical short gamma-ray bursts with ultra-relativistic jets. Instead, we suggest that breakout of a wide-angle, mildly-relativistic cocoon engulfing the jet elegantly explains the low-luminosity gamma-rays, the high-luminosity ultraviolet-optical-infrared and the delayed radio/X-ray emission. We posit that all merging neutron stars may lead to a wide-angle cocoon breakout; sometimes accompanied by a successful jet and sometimes a choked jet.