Acting hours before the House began debating a Democratic trade bill that the White House labeled protectionist, President Reagan yesterday said he will ask four countries to voluntarily cut their exports of machine tools to the United States on national security grounds.

The president said he acted in response to a three-year-old petition by the National Machine Tool Builders Association.

This is the third time in 10 days the White House has moved on pending trade disputes. It threatened Brazil with retaliation if it continues to block sales of U.S. high technology and slapped quotas on imports from Western Europe in retaliation for Common Market trade actions.

The current flurry of activity mirrors White House moves in September, when the administration also was faced with bipartisan demands from Congress for action on a growing trade deficit, which reached a record $148.5 billion last year.

Commerce Secretary Malcolm Baldrige, who read the presidential statement at a White House press briefing, denied the machine-tool action was protectionist and said the timing of the announcement had nothing to do with the Democratic trade bill.

Baldrige said the announcement was set yesterday "because the president made his decision two days ago."

On Capitol Hill, however, the presidential action was seen differently.

"If nothing else, the trade bill brought a decision on machine tools," said Rep. Barbara B. Kennelly (D-Conn.), who has been pushing the administration for action on machine tools.

Chairman Dan Rostenkowski (D-Ill.) of the House Ways and Means Committee, floor leader for the House bill, attacked the presidential move as three and a half years late.

"The moment pressure builds up in Congress for tougher trade policy, the administration lets a little air out of the balloon. . . . Note that the same administration now threatening to veto the House bill as too protectionist takes the very same approach to unfair trade practices: negotiate for voluntary restraints and impose sanctions if that doesn't work," Rostenkowski said.

Rep. Nancy L. Johnson (R-Conn.), whose district has a number of machine-tool manufacturers, cited "a reluctance" on the part of Reagan "to take this kind of action because of his strong free-trade stance."

Reagan called for Japan, West Germany, Taiwan and Switzerland to voluntarily restrain their exports of seven types of machine tools: machining centers, vertical and horizontal numerically controlled (computerized) lathes; non-numerically controlled lathes; milling machines, and numerically and non-numerically controlled punching and shearing machines.

Machine tools are the devices used to make other machines, and to shape planes, tanks, bombs and ships for the military.

Currently, imports in those seven categories account for 56.8 percent of sales. Baldrige refused to detail the level of restraints the administration will seek.

Japan is by far the major supplier in those categories, with U.S. sales last year totaling $673.3 million. Germany was next with sales of $96.9 million, followed by Taiwan, $50.7 million, and Switzerland, $23.4 million, the Commerce Department reported.

Baldrige said he doesn't expect any problems in negotiating the voluntary restraint agreements, which would be similar to limits Japan put on its auto exports and more than a dozen nations have imposed on their steel sales to the United States.

If any supplier balks, however, Reagan will be able to declare that imports threaten the national security and impose quotas directly.

"The possibility of presidential action remains as a hammer over the negotiating process," said Johnson.

In his statement, Reagan cited findings by Baldrige and Defense Secretary Caspar W. Weinberger that "the machine-tool industry is a small, yet vital, component of the U.S. defense base."

The issue has been controversial within the White House ever since the association filed its petition in March 1983 seeking restrictions that would limit imports to 17.5 percent of U.S. sales.

Baldrige concluded 11 months later that "imports posed a national security threat," but that report was sent back for further work by the National Security Council.

The issue surfaced again late last year when Republican congressmen being asked to support a tax overhaul measure complained about the delay in the machine tool case to White House chief of staff Donald T. Regan. Baldrige submitted new recommendations in March.

While applauding the president's decision, James A. Gray, president of the machine-tool association, attacked unnamed officials in the Reagan White House who "impeded the recovery of our industry" by sitting on the report for two years.