After a series of scares and setbacks, President Carter's standby gasoline rationing plan cleared the Senate yesterday on a vote of 58 to 39.

The House will vote on the plan today, and House returns from a whip count indicate an uphill fight. The plan will die unless the House approves it this week.

The administration amended its plan twice in 48 hours in a search for votes, ending up with a formula that would allocate rationin coupons among the states on the basis of their historical use of gasoline rather than, as first proposed, on the number of registered cars in each state.

Yesterday morning, three hours before the vote, Sen. Henry M. Jackson (D-Wash.), its chief sponsor, said the plan was "in deep trouble." He said he could count only 41 votes for the plan.

After the Senate had handed Carter an easy victory, Jackson attributed the outcome to two events - further reassuurances form the president to agriculture and energy interests on supplies of gasoline and a resolution drafted by Republican whip Ted Stevens (Alaska) providing that temporary or regional shortages alone would not trigger nationwide rationing.

Some farm-state senators had been opposed to the plan because it promised adequate gasoline for production of agricultureal goods but said nothing about fuel for food processing or distribution. Jackson obtained a letter from the president five minutes before the scheduled vote promising to protect all steps in the food chain - from farm to consumer - from "serious disruption." Carter sent a second letter promising that, if rationing is ever put into effect, necessary gasoline would be provided off the top for the production of energy such as coal and electricity.

A more serious problem, Jackson said he discovered yesterday morning, was a misunderstanding among many senators as to when rationing might be put into effects. Some feared that a situation such as the current shortage in California would be enough to trigger national rationing, he said.

To ease these fears, Stevens introduced and the Senate passed a resolution stating its feeling that no rationing plan should be put into effect unless there was at least a 20 percent reduction in nationwide gasoline supplies. The plan provides that if the president should decide to put rationing into effect he would have to send the plan back to Congress where it would be subject to a one-house veto. Jackson said he believed the Stevens resolution changed at least 10 votes.

Both party leaders voted for the stanby plan. Majority Leader Robert C. Byrd (D-W. Va.) pleaded with the Senate to "stand up to its responibilities" and put a rationing plan into place before an emergency hits.

Said Jackson: "If there should be a coup in the Mideast, we could wake up one morning and if there's no rationing plan we'd be walking." The Senate was told it would take about nine months to get the rationing machinery ready once Congress has approved a standby plan.

Before approving the plan, the Senate voted 66 to 30 to adopt the president's latest amendment changing the formula for allocating coupons to historical use of gas. This plan would benefit large rural states where people must drive long distances to work and have no mass transit and states where there is heavy tourist traffic.The historical use is measured by the amount of gas purchased in a state whether by residents or others passing through. For this reason, the District of Columbia, Virginia and Maryland would receive more gasoline per capita than the national average.

All Maryland and Virginia senators voted for the plan except John W. Warner (R-Va.).

Supporters of the plan said there is no such thing as a completely equitable rationing plan but that the final product based on historical use was as fair as any method that could be devised.

The House Rules Committee sent the amended plan to the House floor by a vote of 10 to 3 with a recommendation that debate be limited to three hours.