IN RECENT administrations in South Korea a pattern has emerged for how presidents treat Japan. For the first three of their five years in office, they are in a friendly swoon, focusing firmly on the future. Then, as if rudely awoken, they remember that Japan was once a brutal coloniser, and things go swiftly downhill.

Lee Myung-bak, in his last few months as South Korea’s president, is following the same script, but with a twist. On August 10th he made an unexpected visit to an islet that South Korea, which occupies it, calls Dokdo, and that Japan, which covets it, calls Takeshima. That suddenly upset the diplomatic limbo in which the territorial dispute had lain for years. A South Korean president had never set foot on the island before. A few days later Mr Lee added what the Japanese saw as insult to injury, by saying that if the emperor, Akihito, were to visit South Korea, he should first apologise for Japan’s wartime sins. Then followed a Dokdo nonsense, in which the South refused to receive a diplomatic letter and Japan refused to take it back. Even Japan’s relations with North Korea appear to have more scope for improvement.

The question is why Mr Lee, who must leave office shortly after elections in December, is going out of his way to be so provocative. Now that Park Geun-hye, no friend of the president, has become the ruling party’s candidate to contest the elections, Mr Lee looks like a lame duck. His brother, who wielded influence over his administration, was indicted in July on kickback charges, joining other former presidential aides accused of corruption. In a country where ex-presidents’ families and friends are often hounded by their enemies, Mr Lee’s visit to the island can best be explained as a way of shoring up his defences before he goes.

The trouble is, he is not the only diminished leader in the neighbourhood. In late August Yoshihiko Noda, the Japanese prime minister, was defeated in an opposition censure in the upper house, in effect killing his chances of pushing legislation through both houses of parliament during this session.

The immediate consequence is that his government is running out of cash. On September 4th it postponed ¥4.1 trillion ($52.4 billion) in tax grants to towns and cities, following its failure to pass a bill to issue bonds to help fund this year’s budget. Soon, though, the censure motion may leave Mr Noda no choice but to dissolve parliament, pushing him into an autumn election that polls suggest his ruling Democratic Party of Japan (DPJ) will lose. The fight is likely to be liveliest on the nationalist right, where some of the DPJ’s most potent challengers include people spoiling for a verbal confrontation with South Korea. That will make the bilateral tensions even harder to diffuse.

Pundits are struggling to understand how matters deteriorated so swiftly. They are mystified as to why Mr Lee brought the emperor into the fray. The 78-year-old has worked hard to improve relations with South Korea, as with all neighbours who suffered under Japanese imperialism. He is not shy of apologising.

As for the surprise visit to the island, Mr Lee has broken what the Japanese see as a diplomatic taboo. And he has sought to aggravate the thorny territorial issue with the emotive issue of “comfort women”, South Koreans press-ganged during the second world war, along with other nationalities, to provide Japanese soldiers with sex.

A year ago South Korea’s Constitutional Court compelled Mr Lee’s government to take steps to address the grievances of some of the victims who every week hold protests outside the Japanese embassy in Seoul. Park Cheol-hee of Seoul National University reckons that Mr Lee decided to go to the island partly out of frustration, because his government was unable to persuade Mr Noda’s administration to offer compensation to the comfort women, along with profounder apologies than Japan had issued to date.

In South Korea the blame for this fell largely on Mr Noda. However, Hitoshi Tanaka, a Japanese foreign-policy expert who has taken part in comfort-women negotiations in the past, says it was long ago agreed between the two countries that Japan could not offer state handouts to individuals, however much they suffered, on the (admittedly curious) ground that the demands would be endless. He says the Lee administration ignores numerous past apologies, as well as indirect compensation payments.

A big risk now is that the row could inflame anti-Korean sentiment in Japan. Charismatic right-wing politicians such as Toru Hashimoto, mayor of Osaka, who is preparing to launch a nationwide political party to take part in the elections, is one of several influential figures who have called for a review of the 1993 “Kono Statement”, named after the then chief cabinet secretary, which is Japan’s fullest apology for the incidents of sexual slavery. So has Shinzo Abe, a nationalist whose disastrous spell as prime minister has not snuffed out his ambitions. Such a review would infuriate South Koreans.

Deteriorating relations have already had material consequences. In June, and at the last moment, South Korea shelved a deal to share intelligence with Japan, mainly about North Korea. Military exchanges, which are encouraged by the United States, an ally of both countries, were suspended this week. Japan is mulling whether to renew a currency-swap agreement that expires in October. Politicians are even threatening to stop a Korean soap-opera star from visiting Japan, after he took part in a swimming relay to Dokdo. For Japanese women obsessed with the “Korean wave” of popular culture, that is extremely serious.

Five million tourists travel between the two countries each year, and the business ties are so thick that a huge incentive exists for South Korea and Japan to overcome their differences. It will not happen, however, before Mr Lee leaves office. By then, Mr Noda may be gone too.