In this work, the optimal variational iteration method (OVIM) is used to solve partial and ordinary fractional differential equations. The standard variational iteration method (VIM) is reassessed by introducing a parameter that accelerates convergence. The value of the convergence acceleration coefficient is determined by calculating the residual of the parameter within the L2 norm. The numerical results proved that the proposed method gives much better and more accurate results than the standard VIM method, as the effect of adding the parameter to the VIM method and its calculation method was clear in improving the method and increasing the convergence of the solution, where we solved several examples of ordinary and partial fractional differential equations. In addition, the fractional Kawahara and foam drainage equations have also been solved. All results were obtained using the Mathematica®12 program. The results were also compared with the optimal Adomian decomposition method (ADM), and the proposed method showed higher efficiency and better accuracy.