We have studied the magnetic and superconducting properties of Ba(Fe1-xCox)2As2 as a function of temperature and external magnetic field using neutron scattering and muon spin rotation. Below the superconducting transition temperature the magnetic and superconducting order parameters coexist and compete. A magnetic field can significantly enhance the magnetic scattering in the superconducting state, roughly doubling the Bragg intensity at 13.5 T. We perform a microscopic modelling of the data by use of a five-band Hamiltonian relevant to iron pnictides. In the superconducting state, vortices can slow down and freeze spin fluctuations locally. When such regions couple they result in a long-range ordered antiferromagnetic phase producing the enhanced magnetic elastic scattering in agreement with experiments.