We study nanohertz gravitational waves relevant to pulsar timing array experiments from quantum fluctuations in the early universe with null energy condition (NEC) violation. The NEC violation admits accelerated expansion with the scale factor $apropto (-t)^{-p}$ ($p>0$), which gives the tensor spectral index $n_t=2/(p+1)>0$. To evade the constraint from Big Bang nucleosynthesis (BBN), we connect the NEC-violating phase to a subsequent short slow-roll inflationary phase which ends with standard reheating, and thereby reduce the high frequency part of the spectrum. An explicit model is constructed within the cubic Horndeski theory which allows for stable violation of the NEC. We present numerical examples of the background evolution having the different maximal Hubble parameters (which determine the peak amplitude of gravitational waves), the different inflationary Hubble parameters (which determine the amplitudes of high frequency gravitational waves), and different durations of the inflationary phase (which essentially determine the peak frequency of the spectrum). We display the spectra with $n_t=0.8$, $0.9$, and $0.95$ for $flesssim 1/{rm yr}$, which are consistent with the recent NANOGrav result. We also check that they do not contradict the BBN constraint. We discuss how the nearly scale-invariant spectrum of curvature perturbations is produced in the NEC-violating phase.