Working memory is critical to cognition, decoupling behavior from the immediate world. Yet, it is imperfect; internal noise introduces errors into memory representations (1, 2). Such errors accumulate over time (3)(4)(5) and increase with the number of items simultaneously held in working memory (6-10). Here, we show that error-correcting attractor dynamics mitigate the impact of noise on working memory. These dynamics pull memories towards a few stable representations in mnemonic space, inducing a bias in memory representations but reducing the effect of noise. Model-based and model-free analyses show attractor dynamics account for the frequency, bias, and precision of working memory reports in both humans and monkeys. Furthermore, attractor dynamics were optimized to the context; they adapted to the statistics of the environment, such that memories drifted towards contextually-predicted values. Our results suggest attractor dynamics mediate errors in working memory by counteracting noise and integrating contextual information into memories.