Secretary of State Alexander M. Haig Jr. spent much of a 20-hour visit here trying to undo the impression left by a brief comment he made in Washington during the military coup attempt here Feb. 23.

Haig, who told a reporter on first learning of the abortive rebellion that it was "an internal matter," spent much of yesterday and today reiterating U.S. support for Spain's fledgling democracy. Haig's comment had been interpreted here as proof of a callous and even antagonistic attitude toward Spanish democracy on the part of the Reagan administration.

Haig's schedule from late yesterday until he left for London today was a gruelling penance for a momentary lapse: an hour's meeting plus a two-hour "working luncheon" with the foreign minister; a 1 1/2-hour meeting with the prime minister; an hour with the leader of the opposition Socialist Party; an hour with King Juan Carlos, whose firm stand against the coup caused it to collapse 18 hours after it began.

To be sure, there were other things to be discussed, such as the renewal late this year of the U.S.-Spanish military bases agreement and Spain's possible entry into NATO. But hardly anyone on either side pretended that Haig would have been here at this time had it not been the events of Feb. 23 and Haig's widely reported comment.

The biggest part of the uproar was caused, according to U.S. Embassy sources, by Spain's leading news magazine, Cambio 16, which published a cover story shortly after the abortive coup with the title, "Reagan Washed His Hands." The story said the Reagan administration lagged behind other Western governments in condemning the attempted military takeover and said the United States had been ambivalent while the bid was in progress. a

The U.S. Embassy denounced such assertions as "gross and malicious misrepresentations." It flatly denied assertions that the United States knew of the coup attempt in advance.

Haig opened his press conference today, the only such formal press meeting scheduled in his whirlwind eight-day tour of nine countries, with what he called "an important comment" that the United States -- and he personally -- were determined to continue "unflinching support" of democracy in Spain.

Haig turned aside a Spanish journalist's question about what he would have told a fellow general about a coup plot. But at the end of the press conference New York Times bureau chief James Markham got Haig's dander up by asking if he regrets a possible "misapprehension" which may linger in the Spanish military, especially because of the Reagan administration's policies of improving relations with military governments in Latin America.

Addressing Markham as "my friend" in the tone of voice that top sergeants use with privates, Haig responded that the misapprehension may continue "among those whose appetites are insatiable with respect to it."

Haig went on to attribute the stir over his remark to "misunderstanding" in some instances and "mischief" in others. He said he regrets what happened because uncaring words "in no way" represent U.S. policy, and that anyone who persists in thinking so is "either not very bright or terribly mischievous."