In this paper, we investigate the problem of distributed optimization for second-order multi-agent systems with fixed-time flocking. The objective is to concurrently steer the agents towards a common velocity while optimizing the global objective function. To solve the problem, we first design a fixed-time estimator to predict the global gradient of the objective functions, then based on which, each agent is endowed with fixed-time tracking controller to track the optimal solution. Motivated by the fact that the relative velocity information is difficult to obtain accurately, the proposed algorithm is designed without using neighbors’ velocity. The upper bounds of the settling time are provided without relying on the initial states of the agents, only requiring the adjustment of parameters. The effectiveness of the proposed control protocol is also demonstrated through numerical simulations.