This paper studies the connection between a class of mean-field games and a social welfare optimization problem. We consider a mean-field game in function spaces with a large population of agents, and each agent seeks to minimize an individual cost function. The cost functions of different agents are coupled through a mean-field term that depends on the mean of the population states. We show that although the mean-field game is not a potential game, under some mild condition the ϵ-Nash equilibrium of the mean-field game coincides with the optimal solution to a modified social welfare optimization problem. This enables us to study the mean-field equilibrium using standard optimization theory. Based on this connection, we derive new results on the existence and uniqueness of the mean-field equilibrium. We also show that the mean-field equilibrium can be computed by a decentralized primal–dual algorithm. Numerical results are presented to validate the solution, and examples are provided to show the applicability of the proposed approach.