July 4 (Reuters) - Foreign purchases boosted Japanese stocks last week amid a weakening yen and global enthusiasm for artificial intelligence-linked companies, which tempered concerns about the Bank of Japan's policy outlook.

According to exchange data, cross-border investors snapped up Japanese stocks worth a net 604.93 billion yen in the week ending June 28, marking their largest weekly net purchase since April 12.

Investors acquired 480.96 billion yen in derivative contracts and 123.97 billion yen in cash equities, a stark contrast to the previous week's net selling of 603.7 billion yen and 21.37 billion yen, respectively.

Technology-related shares attracted strong demand, with semiconductor testing equipment maker Advantest soaring about 11%, and AI-focused startup investor SoftBank Group climbing around 5% during the week.

The Topix stock index posted its biggest weekly gain since March 12, rising 3.12% last week, while the Nikkei share average increased about 2.56%.

Both indexes closed at record highs on Thursday, supported by optimism over robust corporate performance in the latter half of the year.

However, overseas investors pulled approximately 130.9 billion yen from long-term Japanese bonds, extending net selling to a third consecutive week, data from the Ministry of Finance showed.

They also shed short-term debt securities of a net 1.15 trillion yen, their third straight weekly net disposal.

Japanese investors, meanwhile, pulled out of foreign bonds for a second successive week. They sold 254.4 billion yen worth of long-term and 67.3 billion yen worth of short-term overseas bonds last week.

In the equities market, Japanese investors offloaded 488.8 billion yen worth of foreign securities, after making a net purchase worth 119.3 billion yen in the previous week.

(Reporting by Gaurav Dogra and Patturaja Murugaboopathy in Bengaluru; Editing by Eileen Soreng)