President Reagan and Japanese Prime Minister Yasuhiro Nakasone agreed today to work together to open Japanese markets to U.S. products, and they assigned key Cabinet members to speed the effort.

Their statement followed a 2-hour 40-minute meeting designed to deal with what a senior U.S. official called "mounting frustration" in this country over the growing imbalance in U.S.-Japanese trade. Japan's 1984 trade surplus with the United States is expected to top $35 billion.

"We agreed to work strenuously in the months ahead to open our markets fully and to resist protectionist pressures in both countries," Reagan said in a statement to reporters after the meeting.

In his departure statement, Nakasone called for "a more balanced development of our trade and economic relations" and said: "Japan will promote economic policies that will enhance growth, led by domestic private demand, and will make further market-opening efforts."

The United States is especially interested in opening Japanese markets for products in which this country has a competitive advantage, particularly high-technology electronics, forest products, pharmaceuticals and advanced medical and telecommunications equipment.

A senior U.S. official who briefed reporters after the meeting said the Reagan administration was "very satisfied" with the outcome, adding that when Nakasone gives his word, "his words and his commitments mean something."

The official praised the Japanese leader for his understanding of U.S. concerns, saying: "He came here with our agenda."

Reagan, who considers Nakasone a friend, was said to have stressed that "protectionist pressures in the United States would be impossible to handle" unless the Japanese grant more access to their markets, which the president called the key to improving trade relations.

Those relations dominated a meeting that had been expected to be devoted almost equally to international affairs, especially next week's arms-control talks in Geneva between Secretary of State George P. Shultz and Soviet Foreign Minister Andrei A. Gromyko.

But unlike trade issues, there are relatively few differences between Tokyo and Washington on arms control. On the most sensitive issue of Japanese concern, Reagan reaffirmed the U.S. commitment to "a global approach" on arms control that would prohibit the Soviets from transferring medium-range nuclear weapons from Europe to Asia.

"We can't achieve security for one region at the expense of another," a U.S. official quoted the president as saying.

Surprisingly, the most contentious trade issues at the meeting were raised by Nakasone before Reagan spoke. Both Japanese and U.S. officials said Nakasone was fully aware that Japan's huge trade surplus and the question of its closed markets have become major irritants in the otherwise smooth U.S.-Japan relations.

Speaking of these problems, Nakasone said he was "determined to solve them" and offered his solution of high-level contacts supervised by Shultz and Japanese Foreign Minister Shintaro Abe, who were charged with giving a progress report to Reagan and Nakasone at the May economic summit in Bonn.

U.S. officials said they expect progress even before then to ease the efforts of American manufacturers who are trying to sell sophisticated telecommunications equipment in Japan. On April 1, Japan will shift from a government communications monopoly to a private system stressing competition.

Nakasone said foreign members, including the president of the U.S. Chamber of Commerce in Japan, would serve on an advisory body dealing with the transfer of the telecommunications industry to private hands.

U.S. manufacturers have been concerned that their Japanese competitors would be given an unfair advantage in selling to the private company, but Nakasone pledged to make sure there is no discrimination of this kind.

On another contentious trade issue, Nakasone was quoted by a U.S. official as saying that he hopes to see "a final and successful" solution to keeping Japanese markets open to American software. For the past year, the administration has been concerned that draft regulations proposed by a Japanese government agency would force U.S. manufacturers to give up prorietary information in order to sell in Japan.

Unlike other U.S.-Japanese summit meetings during the Reagan administration, this one focused almost entirely on paving the way for U.S. exports to compete in Japan rather than on restricting Japanese sales in this country.

A U.S. official said the question of continuing "voluntary restraints" on the sale of Japanese autos in the United States did not even come up. The restraints are scheduled to expire March 31.

The friendly relations between Reagan and Nakasone were evident in the language of the statements made at the close of their talks.

"In five meetings, we have helped strengthen the powerful partnership for good between the United States and Japan . . . ," Reagan said.

The president, who had been vacationing in Palm Springs, returned to Washington after the meeting. Nakasone headed back to Japan, with a scheduled rest stop in Honolulu.