SEOUL—The U.S. and South Korea struck an agreement in principle over the costs of their military alliance, ending a monthslong dispute that had loomed over President Trump’s planned second summit with North Korean leader Kim Jong Un.

The two sides have agreed to a preliminary deal covering roughly 28,500 U.S. military personnel in South Korea, though the final details are being sorted out, a U.S. State Department spokeswoman said. The previous agreement expired Dec. 31, though the two sides had until to April 15 to come to...