China has detained two men for 15 days after they were pictured wearing Japanese World War II army uniforms at the site of one of the conflict’s worst atrocities.

The Chinese men, aged 22 and 25, provoked widespread online outrage after posting the images of the prank, which inflamed enduring sensitivities over Japan’s invasion and occupation of much of the China in the 1930s and 1940s.

Nanjing police said the pair were ruled guilty on the broadly defined charge of “picking quarrels and provoking trouble” and sentenced to administrative detention, a punishment short of jailing for which no trial is required.

“Individual actions of citizens should not challenge the dignity of the nation and its people,” police said in a statement. “No behaviour in public settings or in cyberspace can cross the bottom line of the law.”

The men travelled to Nanjing over the Lunar New Year holiday and the pictures were taken in front of a bunker used by Chinese defenders during the 1937 Japanese assault that ended in the notorious Rape of Nanking.

​They sent the photos on the popular QQ messaging service, from where they were reposted around the internet, stirring what police described as “extreme rage and severe condemnation”.

Pictures of the two with faces obscured were posted on many websites. One wore an officer’s uniform and carried a samurai sword, while the other wore puttees and carried what appeared to be a replica rifle.

Police did not say how the men were identified, although social media and government databases may have offered clues.

One of the two had been tracked to the south-western province of Sichuan.

More than 70 years after the war ended, Japan’s relations with China remain fraught.

China’s ruling Communist Party derives much of its legitimacy to rule from its much-mythologised role fighting the Japanese, who were opposed mainly by Chiang Kai-shek’s Nationalists. Many in China also believe Japan has never showed sincere contrition for the conflict, in which an estimated 15 million to 20 million Chinese were killed.

A memorial hall and museum now stand at the site of a mass grave in the Yangtze River city and annual commemorations in December have been attended by President Xi Jinping and other high-ranking leaders.

In 1937, Nanjing was Chiang’s capital, to which he and his army retreated following the Japanese occupation of Shanghai after dogged fighting by the Chinese defenders.