The Senate narrowly defeated an attempt yesterday to force a vote on passage of legislation that would impose economic sanctions against the white-minority government of South Africa, but supporters of the bill vowed to continue their fight until the measure is enacted into law.

The vote was a victory for the Senate Republican leadership and President Reagan, who in an attempt to prevent final passage of the bill Monday issued an executive order imposing a milder version of the sanctions against South Africa contained in the legislation. Reagan has said he will veto the measure if it reaches his desk.

Although another procedural vote on the bill -- the third this week -- is scheduled for today in the Senate, Democratic Whip Alan Cranston (D-Calif.) conceded that the outcome would probably be the same and that Democrats would now concentrate on attaching the sanctions legislation to other measures that are moving toward passage in Congress.

He said this attempt would be made either with a bill to raise the national debt ceiling to $2 trillion or a continuing resolution to fund the government after the start of the new fiscal year Oct. 1, measures that Cranston described as "tough to filibuster" and "very difficult to veto."

"We are going to keep this issue before the Congress and the country until we win," Cranston said.

In yesterday's procedural test, the Senate voted 57 to 41 to shut off further debate on the bill, falling three votes short of the 60 necessary to end the filibuster and force a final vote on passage of the legislation.

On Monday, in the first procedural test of the week, proponents of the bill fell seven votes short of invoking cloture.

Slightly different versions of sanctions legislation overwhelmingly passed the House and the Senate earlier this year, with only a final Senate vote on a conference report resolving the differences necessary to send the bill to the president. But with Senate Democrats pushing for enactment of the legislation and the White House and Senate Republican leaders seeking to avoid a politically damaging veto fight, the debate over South Africa has taken on an increasingly partisan tone.

"This is no longer an issue of what is good for South Africa," Senate Majority Leader Robert J. Dole (R-Kan.) said before yesterday's vote. "It's a raw political issue. South Africa is secondary."

Dole argued that Reagan's executive order, although weaker than the pending legislation, represented a victory for congressional proponents of a tougher line against the South African government and that it is now important for the country to take a unified stand, ending the squabble between the White House and Congress over sanctions.

"I don't care when the president was converted, whether it was one minute ago," Dole said. "The president speaks for the nation on foreign policy."

Democrats denied Republican charges that they seek to embarrass Reagan by confronting him with a choice of vetoing the sanctions legislation or reversing his position even more radically than he did on Monday when he issued the executive order incorporating key provisions of the bill. Noting that the measure initially passed the Senate with strong bipartisan support, Sen. Edward M. Kennedy (D-Mass.) said, "If there are any questions of partisanship, they begin with those who have tried to divide these [bipartisan] forces in the last 48 hours."

However, the Republican charges of partisanship apparently had their desired effect. Sen. Robert T. Stafford (R-Vt.), in explaining his decision to switch sides and support the White House in yesterday's vote, accused the Democrats of playing "political games" with the South Africa issue "in a calculated effort by the Democratic leadership to embarrass the president.

"I wanted no part of that," he added.

Stafford and Sen. Mack Mattingly (R-Ga.), who were among 12 Republicans who defected from the White House Monday, reversed themselves yesterday, providing the margin of victory. Of the seven Republicans who were absent for Monday's vote, only Sen. John H. Chafee (R-R.I.) defied the leadership yesterday and voted with the Democrats.

Democrats lined up solidly in support of cloture, although Minority Leader Robert C. Byrd (D-W.Va.) switched his vote at the last minute for procedural purposes.

Several House members from the Congressional Black Caucus mingled with senators on the floor as the votes were being recorded, a reminder of the strong black support for passage of the sanctions legislation. Rep. Mickey Leland (D-Tex.), chairman of the caucus, said caucus members will "continue to bring their message to individual senators and their constituents until the U.S. government is clearly on record in opposition to the repulsive practices of apartheid."