In this technical note, we investigate an optimal output consensus problem for heterogeneous uncertain nonlinear multi-agent systems. The considered agents are described by high-order nonlinear dynamics subject to both static and dynamic uncertainties. A two-step design, comprising sequential constructions of optimal signal generator and distributed partial stabilization feedback controller, is developed to overcome the difficulties brought by nonlinearities, uncertainties, and optimal requirements. Our study can not only assure an output consensus, but also achieve an optimal agreement characterized by a distributed optimization problem.