We give a characterization of optimal transport plans for a variant of the usual quadratic transport cost introduced in Gozlan, Roberto, Samson and Tetali (J. Funct. Anal. 273 (2017) 3327–3405). Optimal plans are composition of a deterministic transport given by the gradient of a continuously differentiable convex function followed by a martingale coupling. We also establish some connections with Caffarelli's contraction theorem (Caffarelli, Comm. Math. Phys. 214 (2000) 547–563).