One of the main issues in human-robot interaction is to control the forces arising from physical interaction. In this work, it is proposed an optimal admittance force controller for safe physical human-robot interaction (pHRI), which is obtained using optimization tools. First, the performance index of the optimization problem is proposed as the weighted sum of the force tracking error and its time derivative. Then, the impedance model of a robot is considered as an equality constraint, resulting in a dynamic optimization problem (DOP). Moreover, a constraint on the maximum pHRI force is included in the DOP to ensure safe pHRI. Finally, the solution to the DOP is obtained via the gradient flow approach, yielding a pHRI controller easily to implement on-line. The optimal controller modifies the commanded end effector trajectory in order to control the pHRI force and reducing excessive force arising during interaction. A stability proof is given and the implementation of the proposed pHRI controller is successfully verified via experiments.