The effect of doping MgB2 with carbon nanotubes on transition temperature, lattice parameters, critical current density and flux pinning was studied for MgB2–xCx with x = 0, 0.05, 0.1, 0.2, and 0.3. The carbon substitution for B was found to enhance Jc in magnetic fields but depress Tc. The depression of Tc, which is caused by the carbon substitution for B, increases with an increasing doping level, sintering temperature, and duration. By controlling the extent of the substitution and addition of carbon nanotubes we can achieve the optimal improvement on critical current density and flux pinning in magnetic fields while maintaining the minimum reduction in Tc. Under these conditions, Jc was enhanced by two orders of magnitude at 8 T and 5 K and 7 T and 10 K. Jc was more than 10 000 A/cm2 at 20 K and 4 T and 5 K and 8.5 T, respectively.