The path of a flapping airfoil undergoing a combined, nonsinusoidal pitching and plunging motion is optimized for maximum thrust and/or propulsive efficiency. The nonsinusoidal, periodic flapping motion is described using nonuniform rational B splines. A gradient based algorithm is then employed for the optimization of the nonuniform rational B-spline parameters. Unsteady, low speed laminar flows are computed using a Navier-Stokes solver in a parallel computing environment. The numerical evaluation of the gradient vector components, which requires unsteady flow solutions, is also performed in parallel. It is shown that the thrust generation may significantly be increased in comparison to the sinusoidal flapping motion. For a maximum thrust generation, the airfoil stays at about a constant angle of attack during the upstroke and the downstroke, and may reach very high effective angle of attack values. The pitching motion mostly occurs at the minimum and maximum plunge positions.