PURPOSE: Diffusion-weighted MRI is sensitive to incoherent tissue motion, which may confound the measured signal and subsequent analysis. We propose a "motion-compensated" gradient waveform design for tensor-valued diffusion encoding that negates the effects bulk motion and incoherent motion in the ballistic regime. METHODS: Motion compensation was achieved by constraining the magnitude of gradient waveform moment vectors. The constraint was incorporated into a numerical optimization framework, along with existing constraints that account for b-tensor shape, hardware restrictions, and concomitant field gradients. We evaluated the efficacy of encoding and motion compensation in simulations, and we demonstrated the approach by linear and planar b-tensor encoding in a healthy heart in vivo. RESULTS: The optimization framework produced asymmetric motion-compensated waveforms that yielded b-tensors of arbitrary shape with improved efficiency compared with previous designs for tensor-valued encoding, and equivalent efficiency to previous designs for linear (conventional) encoding. Technical feasibility was demonstrated in the heart in vivo, showing vastly improved data quality when using motion compensation. The optimization framework is available online in open source. CONCLUSION: Our gradient waveform design is both more flexible and efficient than previous methods, facilitating tensor-valued diffusion encoding in tissues in which motion would otherwise confound the signal. The proposed design exploits asymmetric encoding times, a single refocusing pulse or multiple refocusing pulses, and integrates compensation for concomitant gradient effects throughout the imaging volume.