President Reagan escaped a potentially dangerous trap on Capitol Hill yesterday when congressional leaders refused to let his $36 billion package of spending cuts be held hostage for a restoration of the $122-a-month minimum Social Security benefit.

After hours of back-room maneuvering and negotiations, Democratic and Republican leaders in both houses agreed to let the House vote today on legislation that would retain the controversial benefit, despite its proposed repeal in the massive budget "reconciliation" bill.

But the agreement stipulated that the benefits legislation will be considered separately from the administration's top-priority spending-cuts bill, and Senate leaders said they planned to shelve the benefits measure for the time being.

"What they got is one more shot before they go home, with a BB gun," Senate Finance Committee Chairman Robert J. Dole (R-Kan.) commented.

Senate Majority Leader Howard H. Baker Jr. (R-Tenn.) said the bill to restore the minimum benefit will be referred to Dole's committee if it passes the House and will then be taken up by the Senate in "routine" fashion, meaning after the five-week congressional recess that is expected to begin next week.

The agreement was endorsed last night by the House Rules Committee, and an aide to Baker said Reagan, in a telephone conversation, indicated that he agreed with the strategy.

Earlier in the day, Rules Committee Chairman Richard Bolling (D-Mo.) held up clearance of the reconciliation bill by his committee, threatening to block passage unless Congress retains the benefit.

"This is a power play by the chairman of the House Rules Committee to get consideration of a very important matter," Bolling told reporters, recalling the kind of power wielded by one of his predecessors, the legendary "Judge" Howard Smith, who used to go off to his Virginia farm to avoid holding meetings to clear the way for legislation he opposed. "I have no farm, unfortunately," Bolling added.

But the tactic ran afoul of a leadership agreement to avoid delaying tactics on final passage of the reconciliation bill, and so the compromise was worked out to give the House a vote on the minimum benefit and shift the onus for its repeal to the Republican-controlled Senate. "The 3 million people who lose their benefits will know precisely why," said House Budget Committee Chairman James R. Jones (D-Okla.).

Both the House and Senate approved repeal of the benefit in their separate versions of the reconciliation legislation, and conferees agreed last week to end the benefits for future recipients in December and for current beneficiaries next March.

But the decision triggered a political backlash in Congress, and there has been mounting pressure for restoration of the benefit, which sets a floor for Social Security retirement benefits regardless of how long a person has worked. About 3 million people receive the minimum benefit.

The administration had pushed for its repeal as a way of saving $7 billion over the next five years. The administration argued that most recipients would qualify for other compensation and probably don't need the benefit anyway, while many Democrats contend that many of the poorest elderly people rely on the benefit for survival.

The leadership agreement appears to pave the way for final action on the spending-cuts package in both the House and Senate today, followed by a speedy conference to resolve relatively minor differences between the two versions of Reagan's tax-cut legislation that were adopted by the House and Senate Wednesday.

Earlier yesterday progress toward a conference on the tax bill also was held up pending resolution of the dispute over the minimum Social Security legislation.

Although the effort to salvage the minimum benefit did not have the official approval of House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.), it appeared to be the House Democrats' last best hope of leaving some imprint on the reconciliation bill.

In addition to Bolling, it was supported by House Majority Leader James C. Wright Jr. (D-Tex.) and more than 125 other House members, mostly Democrats, who signed a resolution sponsored by Rep. Bruce F. Vento (D-Minn.) calling for removal of the minimum benefit repealer from the reconciliation bill.

The Vento resolution also would have blocked passage of any spending cuts legislation that reduced the minimum benefit before the end of the year.

House approval of legislation to restore the benefit is expected in light of a 405-to-13 vote by the House earlier this month in favor of a non-binding resolution urging that Social Security benefits not be reduced for those who are receiving them.

Passage of legislation to that effect would put pressure on the Senate to restore the benefit this fall. Dole said the issue will be considered in September.