Today, population growth and the need for constructing adjacent buildings have raised the likelihood of pounding between adjacent buildings with different dynamic characteristics. The pounding force applied to adjacent buildings during an earthquake is intensive and may cause total or partial damage to structural elements, leading to collapse. It disturbs and complicates the functioning of buildings during and after an earthquake. Therefore, the main aim of this paper is to minimize and, if possible, eliminate the pounding force between two adjacent structures by considering three objective functions. For this aim, the tuned mass damper is utilized here. Also, this paper aims to reduce the number of collisions between different stories of adjacent buildings through a tuned mass damper system. For this purpose, two adjacent steel moment frames with six and ten stories are nonlinearly modeled and validated using the concentrated plasticity model in OpenSees. Moreover, the pounding element is nonlinearly modeled and validated. Then, tuned mass dampers (TMDs) are used on the roofs of the structures. They are optimized in stiffness, mass, and damping coefficient using the grey wolf optimization (GWO) algorithm. Nonlinear time history analysis (NLTHA) is performed under nine far- and near-field earthquakes. The pounding force and structural responses are analyzed, including maximum story acceleration, maximum inter-story drift, and base shear in the TMD-controlled and uncontrolled adjacent buildings. Finally, the Park-Ang damage index is evaluated for the structures with and without the TMD system. It has been found that the maximum pounding force, the maximum acceleration of the stories, the base shear, the drift ratio, and the number of collisions significantly reduce (or omit) in the presence of TMDs when the objective function is considered to be the minimization of the maximum pounding force. It is shown that the maximum pounding force generally declines to zero for this objective function.