Let A and B be almost commuting (i.e., the commutator AB−BA belongs to trace class) self-adjoint operators. We construct a functional calculus φ↦φ(A,B) for functions φ in the Besov class . This functional calculus is linear, the operators φ(A,B) and ψ(A,B) almost commute for , and φ(A,B)=u(A)v(B) whenever φ(s,t)=u(s)v(t). We extend the Helton–Howe trace formula for arbitrary functions in . The main tool is triple operator integrals with integrands in Haagerup-like tensor products of L∞ spaces.