With Republican and Democrats agreeing that they had just been through five intensive days of hearings with a witness of extraordinary abilities, the Senate Foreign Relations Committee yesterday voted 15 to 2 to endorse Alexander M. Haig as the next secretary of state.

Chairman Charles H. Percy (R-Ill.) praised the degree of unanimity reflected in the voting, saying it would strengthen the hand of President-elect Ronald Reagan. Haig and U.S. foreign policy "at a time of peril." Sen. Alan Cranston (D-Calif.), who had been skeptical about the controversial retired general and Nixon White House aide, said most of his doubts had been resolved and that Haig "could be a truly great secretary of state."

The same qualities for which Haig is frequently praised, however, formed the basis for the two votes against him.

"What we had before us," said Sen. Paul Tsongas (D-Mass.), "was an extraordinary man . . . capable, intelligent, tough, pragmatic, [with] a sense of history and a knack of retaining his options . . . all the ingredients necessary for an historic tenure as secretary of state."

But what "we are dealing with here," he continued, "is a high-risk, high-gain opportunity." The risks, he said, are those "inherent in having all those enormous skills not properly focused by a dominant sense of moral purpose. How real is this risk? I honesty don't know," Tsongs said. "I admire talent, capacity and strength," the senator continued that with a sense of moral times, and you have the stuff of legends. Absent that sense of limits, you have the potential for tragedy."

Given these doubts, Tsongas said he had to vote "no." sen. PaulSarbanes (D-Md.) said his view of Haig "as aman of considerable ability" had been "strengthened" by the hearings. But Sarbanes said his primary concern has centered on Haig's "sensitivity to the use of power under a constitutional system and the judgments Generl Haig would make in this regard." Citing Haig's onetime role as chief of staff to Nixon White House, Sarbanes said that while his efforts to get Haig: to make "value judgements" on those abuses " brought some reassurance," his "concerns remain too strong to support the nomination."

During the hearings, Sarbanes had repeatedly pressed Haig to say whether he thought the abuses of the Watergate era were right or wrong. Haig reacted initially and sometimes angrily by defending his own actions, saying he had inherited most of the problems, had done nothing wrong or illegal and that Nixon was entitled to loyalty and assistance.

Later in the hearings, after a recess, Haig produced a statement making some of the judgements Sarbanes had pressed for. Haig called the 1972 break-in at Democratic headquarters and subsequent obstruction of justice "improper, illegal and inmoral . . . an affront to the fundamental values I cherish and we all share."

Sen. Joseph Biden (D-Del.), who had also been critical of Haig, said that it was Haig's firm commitments to the committee on legal and congressional matters that convinced him to cast a "yes" vote.

Biden called Haig "a man of his word who, once committed, adheres strictly to the fulfillment of his commitments. It is this character trait, which was at times most troubling to me about General Haig's past," Biden said, "which gives me the most hope for his future."

Despite lingering doubts of some Democrats, there was widespread bipartisan agreement that the tough grilling of Haig had dispelled some of the skepticism about him and that he emerged from the process in better shape to be an effective secretary than he was at the outset.

Percy said Haig's nomination along with the rest of the Reagan Cabinet, will reach the full Senate for confirmation on Inauguration Day Tuesday. Percy said it would probably be Wednesday, however, before the Senate gets to Haig. He said one Republican, Sen Lowell Weicker of Connecticut, would speak for the Senate floor against Haig but that there would be no effort to block the confirmation, which Sen. Cranston confirmed on the Democratic side.

In a related action, the committee agreed to continue "all reasonable efforts" to get logs of tape recordings of White House conversations between Haig and Nixon and other material involving Haig. The committee has subpoenaed those logs but a spokesman for the National Archives, where the logs are stored, said they expected an official objection by Nixon's lawyers, which would lead to another five-day delay while Nixon decides on court action.

By then, Reagan will be president. Nixon's lawyer, R. Stanley Mortenson, says that it would be up to Reagan initially to decide if the executive branch wants the logs released.

The committee revealed that Mortenson, on behalf of Nixon, had also objected on grounds of privilege to release of many other documents requested by Sen. Claiborne Pell (D-R.I.) that relate to Haig's role in White House actions on Cambodia, Vietnam and Chile in the early 1970s.

Michael H. Cardozo, deputy counsel to President Carter, told the committee that "all of the documents are highly classified minutes" of some 25 meetings of top-level National Security Council, seven of which Haig chaired. Cardozo said it would take considerable time to review the material to determine if access could be granted without adversely affecting foreign policy, jeopardizing intelligence sources of "chilling the frankness of the advice available to future presidents."