A Japanese court has ruled that Prime Minister Junichiro Koizumi's visits to a controversial shrine are illegal.
Koizumi has been to the shrine four times in three years
A number of war criminals are honoured at the Yasukuni shrine, which Mr Koizumi has visited four times since taking office in 2001.
A district court said that the visits breached Japan's constitutional separation of religion and state.
But Mr Koizumi said that he found the ruling "strange" and would go to the shrine again in the future.
"I don't know why it violated the constitution," he said.
Government officials have argued that Mr Koizumi's visits were made as a private citizen and therefore did not breach the constitutional separation of church and state.
The BBC's Tokyo correspondent says the Japanese public is divided over the shrine's symbolism, with vocal minorities on the right and left supporting and opposing the prime minister's visits.
Built in 1869 to honour victims of the Boshin Civil War
Now venerates the souls of 2.5m of Japan's war dead
Those enshrined include 14 Class A war criminals
The hearing in Fukuoka, southern Japan, concerned a visit made by the prime minister to Yasukuni in August 2001.
The case had been brought by 211 people, some of whom were relatives of war dead and other members of religious groups.
"This is a fantastic ruling that clearly acknowledges the prime minister's visit to Yasukuni as unconstitutional," said Tsuneaki Gunjima, leader of the plaintiffs, on Wednesday.
Chief Justice Kiyonaga Kamegawa ruled that Mr Koizumi had made the visit in his official capacity as prime minister.
Other groups have brought similar cases in the past, but this is the first time that a court has ruled against the prime minister.
However, Mr Kamegawa rejected claims for compensation from plaintiffs who said they had suffered mental anguish.
Last month, another district court threw out a case in which relatives of war dead had tried to stop Mr Koizumi visiting the shrine.
Neighbouring countries, who suffered from Japanese militarism and colonialism in the years before and during the Second World War, have frequently complained about Mr Koizumi's visits - the most recent of which took place on 1 January.
South Korea and China both made diplomatic protests, with Beijing's Deputy Foreign Minister Wang Yi expressing what he called "righteous indignation" on behalf of the people of Asia.
On Wednesday, a South Korean government official who did not wish to be named told Reuters news agency it was "difficult to imagine" that the ruling would put an end to the issue.
The China Daily, China's leading state newspaper, said in a commentary that Mr Koizumi's repeated visits to the Yasukuni Shrine had tied
relations with Beijing "in a fast knot".
Among those honoured at Yasukuni are Japan's wartime Prime Minister Hideki Tojo, hanged for war crimes in 1948.
In earlier comments about the controversy, Mr Koizumi suggested it was wrong to "comment about another country's respect of its history, traditions or customs".