Ambient magnetic field, if trapped in the penetration depth, leads to the residual resistance and therefore sets the limit for the achievable quality factors in superconducting niobium resonators for particle accelerators. Here we show that a complete expulsion of the magnetic flux can be performed and leads to: 1) record quality factors $Q > 2times10^{11}$ up to accelerating gradient of 22 MV/m; 2) $Qsim3times10^{10}$ at 2 K and 16 MV/m in up to 190 mG magnetic fields. This is achieved by large thermal gradients at the normal/superconducting phase front during the cooldown. Our findings open up a way to ultra-high quality factors at low temperatures and show an alternative to the sophisticated magnetic shielding implemented in modern superconducting accelerators.