TOKYO -- Justin Bieber apologized Wednesday to those he offended by visiting a Japanese war shrine, saying he thought it was a beautiful site and only a place of prayer.

The Yasukuni Shrine in central Tokyo enshrines 2.5 million war dead, including Japan's 14 convicted war criminals, and operates a war museum that defends Japan's wartime aggression. It is a flashpoint between Japan and its neighbours that see the shrine as distinct from other Shinto-style establishments mainly honouring gods of nature. China and South Korea in particular see Yasukuni as a symbol of Japan's past militarism and consider Japanese officials' visits there as a lack of understanding or remorse over wartime history.

Two images posted on Bieber's Instagram account were met with outrage from Chinese officials and by commenters on social media. Chinese Foreign Ministry spokesman Qin Gang said the pop star should remember China's position on Yasukuni.

"I hope this Canadian singer, after his visit, can have some knowledge of the Japanese militaristic history of external aggression and their militaristic thinking," he said.

Yasukuni confirmed Bieber visited earlier this week in what appeared to be a personal trip to Japan. A Yasukuni official, who spoke on condition of anonymity citing privacy of a specific visitor, said he strolled in the shrine's precincts, like other ordinary tourists, and most people didn't seem to notice.

The two photos, which were subsequently removed, showed Bieber praying outdoors at the shrine and standing beside a Shinto priest. The Yasukuni official said Bieber did not pray in the shrine's main prayer hall.

In a new Instagram post Wednesday evening, Bieber said he asked his driver to stop when he saw the "beautiful shrine," located in the capital's central district near Budokan hall, where he performed a concert in 2011. It's also near the Imperial Palace and other places tourists visit to see cherry blossoms, though they've mostly finished blooming.

"I was mislead (sic) to think the Shrines were only a place of prayer. To anyone I have offended I am extremely sorry," the post said.

Bieber, 20, gained stardom with his debut album at age 15 but has had a string of recent legal troubles and criticism for perceived cultural insensitivity. Last year he wrote in the guestbook at the Anne Frank House museum that he hoped the Jewish teenager who died in a Nazi concentration camp "would have been a Belieber" -- or a fan of his -- if history were different. And he apologized after appearing to drag two Argentine flags off stage with his feet and a microphone stand during a concert there last year.

He's scheduled to go on trial in Miami in July on charges of driving under the influence and resisting arrest. A misdemeanour assault case in Toronto is awaiting trial, and Los Angeles prosecutors are considering whether to bring a felony vandalism case against Bieber over eggs thrown at a neighbour's house in January.

The Yasukuni Shrine holds a spring festival April 21-23, a major event that already has drawn attention this week. Two of Japan's Cabinet ministers and nearly 150 lawmakers prayed at the shrine, triggering outrage from Beijing and Seoul.

Prime Minister Shinzo Abe has visited the shrine once during his current term in office, last December, worsening ties with those countries and triggered Washington's concerns. He sent a religious offering to the shrine on Monday, an indication he may not visit during the spring festival.