Japanese Prime Minister Masayoshi Ohira completed a visit to Peking today with the announcement of a major low-cost loan for several Chinese modernization projects and an agreement for joint Sino-Japanese drilling of the potentially oil rich Bohai Gulf.

In a joint communique and at a press conference, Ohira said Japan planned to extend more than $200 million in loans in fiscal year 1979 for six railway, port and hydroelectric projects.

Diplomats said Tokyo had actually committed a total of $1.5 billion to the projects.

In a speech this morning, Ohira strongly endorsed China's modernization program and said good relations between Japan, Asia's richest nation, and China, its largest, must contribute to the stability of Asia and moreover of the world."

The agreement for exploration for oil in the Bohai Gulf on China's northeast coast was signed yesterday and marked the first time that the Chinese had agreed to foreign participation in the development of its oil fields. Diplomats said they expected American and British companies now conducting seismic surveys along other parts of China's coast would eventually sign similar offshore agreements with the Chinese.

Organizations controlled by the two governments, the Japan National Oil Corp. and the Chinese Oil and Gas Exploration Development Corp., agreed to cooperate in drilling two areas of the shallow Bohai covering about 10,000 square miles. The Japanese agreed to spend $210 million on exploration, and then each side would spend $500 million to build oil production facilities. Under the agreement, the Japanese would take 42.5 percent of any oil produced. Both sides would share the losses if wells came up dry.

The agreements underlined the healthy state of relations between Asia's two giants, whose mutual quest for economic progress has overcome decades of distrust. Ohira acknowledged that Tokyo differed with Peking on such issues as Japan's promised aid to Vietnam, but said the differences were minor.

The Chinese for the last few years have admired openly Japan's success at overcoming economic obstacles now standing in China's way. The high level of farm productivity in Japan, its rapid recovery from the ravages of World War II and its ability to adopt Western technology while still preserving as Eastern culture have impressed the Chinese.

To help future contacts, Ohira said Chinese students would be welcome in Japan and his government planned to fund Japanese language training in China.

This is the first visit by a Japanese prime minister since 1972, when Japan resumed full diplomatic relations with Peking. Premier Hua Guofeng, who met twoce with Ohira, accepted an invitation to visit Japan in May. Ohira also promised the Chinese help in building a new hospital in Peking and said Tokyo would extend tariff preferences to China beginning in April.

Ohira indicated that he and the Chinese leaders had held lengthy discussions of the situation in Korea. The Japanese leader said the Chinese assured him North Korea would not attack the south.

Japanese diplomats emphasized repeatedly three principles for economic aid to China: no military aid, balance of aid between China and other Asian nations and coordination of aid with what Peking would be receiving from the United States and Western Europe.