The optimal ecological performance of an irreversible air-standard Otto cycle with heat transfer, friction and internal irreversibility is analyzed by using finite-time thermodynamics. The relations between the ecological function and the power output as well as between the ecological function and the efficiency of the cycle are derived by detailed numerical examples. Moreover, the effects of internal irreversibility, heat transfer loss and friction loss on the cycle performance are analyzed. The results indicate that the optimization of the exergy-based ecological function not only represents a compromise between the power output and the rate of entropy generation but also represents a compromise between the power output and the thermal efficiency. This work can provide guidelines for the design of practical internal combustion engines.