The Senate yesterday flexed its muscles on trade, voting in favor of legislation that would sharply curtail imports of textiles and shoes but which faces an almost certain veto.

But, caught in a procedural muddle that the leadership said threatened efforts to reduce the budget deficit, the Senate stopped short of final passage of the measure.

Nonetheless, the 54-to-42 vote for the textile-and-shoe measure showed that congressional demands for action on record trade deficits remain strong. The measure got one more vote yesterday than it did in another test vote three weeks ago.

Sentiment for the measure was so strong yesterday that Senate Majority Leader Robert J. Dole (R-Kan.) and Senate Budget Committee Chairman Pete V. Domenici (R-N.M.) could not prevent their colleagues from attaching the legislation to the reconciliation bill on the floor. To save the budget measure from a flood of other amendments, Dole pulled it off the floor soon after the initial test vote on the textile-and-shoe provision.

The budget bill is the second major piece of legislation that Dole has been forced to withdraw because an amendment containing the textile measure threatened its passage.

The House earlier approved a bill calling for sharper cuts in imports of textiles, but omitting protection for the American shoe industry. The House vote was 262 to 159.

However, both yesterday's Senate vote and the Oct. 10 House vote fell short of the two-thirds majority needed to override the expected presidential veto.

House supporters said this fall's White House counterattack on trade, which was in response to bipartisan congressional support for tougher measures against imports, cost the textile bill at least 30 votes.

Since Labor Day, President Reagan has made four speeches on trade and has proposed a more aggressive program to fight unfair trade tactics by other nations that cost the United States sales abroad and lead to a flood of imports here.

The White House also switched positions and agreed to coordinated intervention with Germany, Britain, France and Japan to lower the value of the dollar. Most experts blame a supercharged dollar for at least half of the record trade deficit, which is expected to soar to $150 billion this year.

The textile bill, with more than half the Senate and two-thirds of the House as co-sponsors, became the leading congressional action on trade. It has the aggressive backing of an industry and labor coalition as well as bipartisan support from lawmakers in the southern textile-producing states.

Supporters of the textile-and-shoe measure, led by Sens. Strom Thurmond (R-S.C.) and Ernest F. Hollings (D-S.C.), said they were forced to attach their bill to the budget action to forestall a threatened filibuster by Sen. Daniel J. Evans (R-Wash.).

Thurmond and Hollings argued that surging imports had cost the American textile industry 350,000 jobs over the past five years.

Maine Sens. George J. Mitchell (D) and William S. Cohen (R) said the shoe measure was needed to preserve an industry that has been decimated by surging imports. Part of the congressional pressure on trade resulted from Reagan's refusal to follow the recommendation of the International Trade Commission that the domestic shoe industry get protection from imports.

"It's just a question of whether you want to keep jobs in America or send them abroad," Thurmond said.

"We are now at a crisis stage, not only in textiles but in a whole range of industries," Hollings said.

Opponents of the bill, led by Evans and Sen. Phil Gramm (R-Tex.), said U.S. textile makers do not need protection and that the bill would bring retaliation against other U.S. industries that depend on exports as well as foreign sales of farm products.

Sen. John C. Danforth (R-Mo.), refusing to support the measure even though he argued in favor of trade protection for the shoe industry, said the bill violates 32 bilateral agreements and the multi-fiber agreement on textiles.

The textile provision would reduce exports by as much as 30 percent from the leading textile suppliers -- South Korea, Taiwan and Hong Kong -- and freeze other exports from other textile-producing nations at 1984 sales levels. The footwear provision would limit annual imports to 60 percent of the U.S. market for eight years.