We discuss quantum annealing of the two-dimensional transverse-field Ising model on a D-Wave device, encoded on $L times L$ lattices with $L le 32$. Analyzing the residual energy and deviation from maximal magnetization in the final classical state, we find an optimal $L$ dependent annealing rate $v$ for which the two quantities are minimized. The results are well described by a phenomenological model with two powers of $v$ and $L$-dependent prefactors to describe the competing effects of reduced quantum fluctuations (for which we see evidence of the Kibble-Zurek mechanism) and increasing noise impact when $v$ is lowered. The same scaling form also describes results of numerical solutions of a transverse-field Ising model with the spins coupled to noise sources. We explain why the optimal annealing time is much longer than the coherence time of the individual qubits.