SEOUL, South Korea — More than 70 years after the end of World War II, South Korea and Japan reached a landmark agreement on Monday to resolve their dispute over Korean women who were forced to serve as sex slaves for Japan’s Imperial Army.

The agreement, in which Japan made an apology and promised an $8.3 million payment that would provide care for the women, was intended to remove one of the most intractable logjams in relations between South Korea and Japan, both crucial allies to the United States. The so-called comfort women have been the most painful legacy of Japan’s colonial rule of Korea, which lasted from 1910 until Japan’s defeat in 1945.

The Japanese and South Korean foreign ministers, announcing the agreement in Seoul, said each side considered it a “final and irreversible resolution” of the issue.

The apology and the payment, which, unlike a previous fund, will come directly from the Japanese government, represent a compromise for Japan’s prime minister, Shinzo Abe, who has often been reluctant to offer contrition for his country’s militarist past.