A constrained optimization problem based on the Lagrange multipliers method is formulated to derive the circulating current references of Modular Multilevel Converters (MMC) directly in abc coordinates. The resulting analytic expressions for calculating the circulating current reference signals are designed to eliminate oscillations in the dc-side power flow, independently from the ac-side operation of the MMC. As a result of the constrained optimization, the circulating currents are shaped to optimally utilize the degrees of freedom provided by the internal energy buffering capacity of the MMC, to effectively decouple the ac grid conditions from the dc bus. This property of the proposed control method makes it especially suitable for preventing oscillations due to unbalanced ac grid voltage conditions from propagating into multi-terminal HVDC systems. It is shown that the power flow at the dc-side of the MMC will be most effectively decoupled from ac-side transients if the desired steady-state power flow is imposed by acting directly on the circulating current references instead of by acting on the acside current references. The operation of an MMC controlled by the proposed approach is demonstrated by simulation studies, verifying the ability of keeping the dc power flow free of second harmonic oscillations, independently of the power control objectives applied for calculating the ac-side current references of the converter.