An extracellular polymeric substance quickly chelates mercury(II) with N-heterocyclic groups.