WASHINGTON (AP) _ Two senior CIA officials, including the No. 2 officer in the agency's clandestine branch, have quit rather than accept demotions indirectly linked to the Aldrich Ames spy scandal, an agency official said Wednesday.

The two are Frank Anderson, head of Near East operations, and John McGaffney, associate deputy director of operations, which is the second- ranking position in the clandestine service in which Ames worked until his arrest last February.

An agency official, who discussed the matter Wednesday night on condition he not be identified, said Anderson and McGaffney were not among 11 CIA officers reprimanded last month for lapses that allowed Ames to operate as a Soviet spy.

CIA Director R. James Woolsey decided Anderson and McGaffney must ''step down to less prominent jobs'' after he learned that Anderson had recommended an award for an officer at a time when Woolsey had frozen awards for all officials who were subjects of an internal CIA investigation into the handling of the Ames case, the official said.

The officer nominated for the award, Milton Beardon, was a station chief working under Anderson. He was among many agency officials whose actions during Ames' nearly nine years of spying came under scrutiny by the CIA inspector general.

Beardon was among the 11 officers whom Woolsey decided to reprimand - but not fire or demote - on the basis of the conclusions reached by the inspector general. Beardon submitted his retirement papers before Woolsey announced the reprimands last month. The agency has not said what connection Beardon had to Ames.

McGaffney approved Anderson's nomination of Beardon for the award, the CIA official said Wednesday.

Woolsey announced at a staff meeting Wednesday at CIA headquarters that he decided it had been ''a serious error in judgment'' for Anderson to have nominated Beardon and for McGaffney to have approved the award in spite of Woolsey's ban.

Rather than accept the demotions by Woolsey, Anderson and McGaffney chose to leave the agency, the official said. He said it was not clear whether they resigned or retired.

Woolsey drew heated criticism from many in Congress for not having fired or demoted any senior officials whom the CIA inspector general said were at least partly to blame for allowing Ames to do his spying without detection for so long.