Price protection for a second major commodity, the politically venerated peanut, was partially shelled yesterday by a cranky Senate.

An effort by Sen. Richard G. Lugar (R-Ind.) to revamp the peanut program completely was defeated narrowly but only after hours of frantic caucusing and deal cutting by southern peanut supporters.

The Senate nonetheless dealt a blow to the exclusive peanut-growing industry, just as it had done the day before in rejecting dairy industry demands for higher price supports in the new farm bill.

Compromise came with an amendment by Sen. Mack Mattingly (R-Ga.), supplanting Lugar, on a 51-to-47 vote.

The amendment would end the system of acreage allotments--government growing franchises held by about 59,000 people--but continue poundage quotas. In effect, current growers would be allowed to obtain federal price-support loans, while new growers are restricted to selling only for export without federal support loans.

Lugar's near victory set off a frenzy of lobbying, huddling and flights of rhetoric, leading Sen. Howell Heflin (D-Ala.) to call the lucrative leasing of peanut allotments "as much a part of America as McDonald's."

Before the vote, growers and lobbyists milled about, seeking sympathetic ears. Agriculture Secretary John R. Block and his deputies darted from meeting to meeting.

In the wake of Lugar's assault, the once-invincible farm-interest coalition threatened to come apart at the seams. Embittered milk-state senators, smarting from their earlier loss, joined consumerists and free-market ideologues in pushing peanut-state legislators into compromise.

Majority Leader Howard H. Baker Jr. (R-Tenn.) said final action on the bill will be completed by tonight but, with menacing fights still looming on tobacco, sugar and target-price subsidies, the peanut issue was relatively small stuff.

Some senators and farm groups were urging Agriculture Committee Chairman Jesse Helms (R-N.C.) to remove the bill from the Senate calendar and try to reconstitute the failing farm coalition. Sen. John Melcher (D-Mont.) charged that the Reagan administration, with 11th-hour demands for more budget cuts, had "dynamited" the coalition and "made it impossible to agree on any bill."

But Helms was busy for the moment with peanuts, an important crop in his state. Seeing his leadership challenged for a second consecutive day by a Republican committee colleague, Helms threatened to retaliate against other commodities. "As they say in North Carolina, how do you like them apples?" he said.

Helms, a champion of budget reductions for food stamps and other social welfare programs, begged the Senate to consider "what this Lugar amendment will do to human beings." He insisted that the peanut industry needs the exclusive acreage and poundage protections afforded under present law.

Heflin put the peanut allotments in a class with the American flag and apple pie. He worried about aged widows and farmers "in their golden years" who would lose their growing allotments under the Lugar amendment.

Heflin equated the allotments to fast-food franchises, asking "Is there something un-American about franchises? Something un-American about McDonald's, Roy Rogers or Hardee's? . . . . Is there something evil about a widow leasing her land?"

Heflin's oratory brought chuckles, but Sen. Paul E. Tsongas (D-Mass.), scolding and sardonic, reminded the Senate that Helms and fellow North Carolinian Sen. John P. East (R) were among the evangels of a conservatism that features free-market economics.

"There is a sense ultimately of hypocrisy," Tsongas said. "If you are going to cut school lunches and cut college loans and keep this peanut program intact, you can do it. But you'll pay a price . . . . We have to hold the Senate to President Reagan's commitment to the free enterprise system."

The gist of Lugar's attack on peanuts was that the program represents what he termed a textbook example of special interests obtaining and maintaining control over an important segment of the farm economy. His argument was undercut somewhat by the president's acceptance of a continued peanut program in return for southern votes on tax and budget legislation this summer.

That deal and a similar arrangement on sugar, in the view of some senators and lobbyists, contributed to undermining the once solid front of farm groups.

Block said that the administration remains committed to House-passed protection for peanuts, but he worried openly about the unraveling coalition and its threat to passage of the bill.

On the Mattingly amendment, Virginia senators Harry F. Byrd Jr. (Ind.) and John W. Warner (R) voted yes, and Maryland's Paul S. Sarbanes (D) and Charles McC. Mathias Jr. (R) voted no.