Both houses of Congress, defying veto threats from the White House, yesterday approved emergency credit relief for debt-ridden farmers facing bankruptcy on the eve of the spring planting season.

While the 318-to-103 vote in the Democratic-controlled House came as no surprise, successive votes of 54 to 45 and 50 to 48 in the Republican-run Senate amounted to major defeats for President Reagan and Senate Majority Leader Robert J. Dole (R-Kan.), who had lobbied hard against the aid measures.

Presidential spokesman Larry Speakes told reporters that Reagan's advisers will be unanimous in recommending a veto of what Speakes called the "budget-busting" legislation.

However, the veto threat, coupled with the fact that the Senate votes fell short of the two-thirds required to override a veto, cast doubt over whether the measures will become law.

Dole predicted they will not, and in a last-minute maneuver the Senate leadership sent its bill to conference with the House in a form that could enable the farm provisions to be stricken.

The measures, approved in different form by the two houses, would provide additional funds for farm-loan guarantees, ease terms for both direct government loans and federal guarantees of commercial loans and force a speedup in processing the aid. The House approved $3 billion in additional loan guarantees; the Senate approved $1.8 billion.

They would also allow farmers to get half their price-support loans, up to $50,000 per farmer, in the spring instead of after the fall harvest, as current law provides.

In addition, the Senate measure would provide $100 million to subsidize lower interest rates for commercial loans, which critics called a bank bailout. The House bill does not contain a similar provision.

Congressional approval of the measures followed an intense lobbying effort by midwestern farmers and public officials, including virtually the entire South Dakota legislature, on behalf of the legislation.

Yesterday farm state lawmakers planted white crosses near the White House in a mock funeral for farms that they said go bankrupt each day.

In vain, Dole angrily reproached his colleagues for approving the emergency farm aid when Senate leaders are trying to find a way to reduce federal deficits.

"If the membership doesn't care about deficits, I'm not sure the leadership does," Dole said. "We're demonstrating we don't have the will to face up to the deficit."

Despite Dole's comments, the Senate voted, 55 to 43, against a proposal by Sen. Phil Gramm (R-Tex.) to prevent implementation of the farm legislation if it would add to federal deficits.

House members also indicated that heavy lobbying by politically powerful groups would likely continue to pay off, despite pressures to reduce deficits by containing spending. "In government, the squeaky wheel gets the grease," said House Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.).

The House measure was approved as a separate bill; the Senate provisions were attached to a bill providing $175 million in disaster and refugee relief for starving Africans, which was finally approved, 62 to 35. The House approved a similar African relief bill earlier this week.

Even without the farm provisions, the White House had indicated that Reagan may veto the African relief legislation as too costly.

The House bill, authored by Rep. Thomas A. Daschle (D-S.D.), was approved after three hours of nearly unanimous praise for the measure as much-needed short-term relief for farm areas.

In the final vote, 234 Democrats and 84 Republicans voted for the bill; 10 Democrats and 93 Republicans voted against it.

In addition to authorizing spring advances on fall price-support loans, the House bill would expand the federal loan-guarantee program, allowing the government to guarantee an addition $3 billion in loans to farmers who would be unable to get credit otherwise.

It would speed up the time for processing loans, provide for reduced interest rates to victims of multiple weather disasters and ease the terms for existing debt-adjustment programs.

"This bill is not going to bail out the big banks . . . it is not going to break the budget . . . it is not going to provide a long-term solution," Daschle said. "What is will do is build a bridge in the hope that it will lead to a vastly improved farm economy very soon."

"This is a Band-Aid approach, but it's also a matter of survivability," said Rep. E. Thomas Coleman (R-Mo.). "If we don't provide this survival kit today, we'll see thousands upon thousands" of farmers going under.

But a few GOP lawmakers, reflecting White House concern about the potential price tag of the bill, said the legislation was too costly and unnecessary in light of recent administration initiatives designed to help farmers.

Administration officials have said the bill could cost $1.6 billion to $9 billion over the next two years, depending on how many farmers paid back federally guaranteed loans. But the Congressional Budget Office estimated the cost at $455 million over the next five years.

Rep. Delbert L. Latta (R-Ohio), ranking Republican on the House Budget Committee, said the adminstration had determined that the measures would cause "a substantial increase in federal spending" and termed the provision allowing farmers to get fall price-support loans this spring "unprecedented."

But Rep. Vin Weber (R-Minn.), responding to charges that the bill was a "bailout," said, "it is simply not the case . . . . We are talking today about good, efficient, honest people who are in trouble . . . through no fault of their own."

Eight Senate Republicans broke ranks to vote for the farm measure. They were Mark Andrews (N.D.), Charles E. Grassley (Iowa), Larry Pressler (S.D.), James Abdnor (S.D.), Robert W. Kasten Jr. (Wis.), John C. Danforth (Mo.), David F. Durenberger (Minn.) and Lowell P. Weicker Jr. (Conn.).