High-temperature superconductivity in iron pnictides occurs when electrons are doped into their antiferromagnetic (AF) parent compounds. In addition to inducing superconductivity, electron-doping also changes the static commensurate AF order in the undoped parent compounds into short-range incommensurate AF order near optimal superconductivity. Here we use neutron scattering to demonstrate that the incommensurate AF order in BaFe$_{2-x}$Ni$_{x}$As$_{2}$ is not a spin-density-wave arising from the itinerant electrons in nested Fermi surfaces, but consistent with a cluster spin glass in the matrix of the superconducting phase. Therefore, optimal superconductivity in iron pnictides coexists and competes with a mesoscopically separated cluster spin glass phase, much different from the homogeneous coexisting AF and superconducting phases in the underdoped regime.