TOKYO — A diplomatic showdown between Japan and China that began two weeks ago with the arrest of the captain of a Chinese trawler near disputed islands ended Friday when Tokyo accepted Beijing’s demands for his immediate release, a concession that appeared to mark a humiliating retreat in a Pacific test of wills.

Japan freed the captain, Zhan Qixiong, 41, who left Saturday on a chartered flight sent by the Chinese government to take him home. Mr. Zhan had been held by the Japanese authorities since his boat collided with Japanese patrol vessels on Sept. 7 near uninhabited islands in the East China Sea, and Japan had insisted that he would be prosecuted.

His release handed a significant victory to Chinese leaders, who have ratcheted up the pressure on Japan with verbal threats and economic sanctions.

“It certainly appears that Japan gave in,” said Hiroshi Nakanishi, a professor of international relations at Kyoto University. “This is going to raise questions about why Japan pushed the issue in the first place, if it couldn’t follow through with meeting China’s challenges.”