The paper is concerned with the distributed optimization problem (DOP) for a class of uncertain multi-input-multi-output (MIMO) nonlinear multi-agent systems with arbitrary relative degree. The target is to design distributed control laws such that the outputs of the agent systems converge to a consensus value and on which the sum of the local cost functions is minimized. By introducing pseudo gradient technique, internal model technique and adaptive control technique, a novel state based distributed control law is firstly constructed. An incremental type Lyapunov function based approach is presented to show that the proposed DOP is solved by the state based control law without requiring the eigenvalue information of Laplacian matrix. By further introducing distributed high-gain observer technique, an output based distributed control law is constructed and by which the DOP is solved under some mild assumption. The proposed control laws are validated on a group of Euler-Lagrange systems, a group of robot manipulators with flexible joints and a group of Chua circuit systems. The simulation results illustrate the effectiveness of the proposed methods.