The president of the Federal National Mortgage Association was named yesterday to head the troubled Mellon Bank Corp., leaving the Washington mortgage finance giant without a No. 2 executive for the second time in a year.

Frank V. Cahouet, a 55-year-old banking industry veteran who had been regarded as a leading candidate to succeed Fannie Mae Chairman and Chief Executive Officer David O. Maxwell, resigned as chief operating officer after only nine months on the job.

At a board meeting yesterday, directors of the Pittsburgh-based Mellon Bank Corp. named Cahouet chairman and chief executive officer, succeeding caretaker chairman Nathan W. Pearson. The previous chief executive, J. David Barnes, stepped down in April after the bank reported a first-quarter loss of $59.8 million, the first quarterly loss in its 118-year history.

Cahouet has an excellent reputation in the banking industry after 24 years at Security Pacific National Bank and two years at Crocker National Bank, during which he was credited with bringing the financially troubled San Francisco bank back to fiscal health.

He arrived at Fannie Mae last September and was responsible for its day-to-day operations, reporting directly to Maxwell. Fannie Mae, a congressionally chartered, publicly traded company, buys mortgages from lending institutions and repackages them into securities for sale to investors. It is the country's largest supplier of capital for home mortgages.

At Fannie Mae, Cahouet succeeded Mark J. Riedy, who left last summer, reportedly after disputes with Maxwell. Cahouet was the fourth Fannie Mae president since Maxwell took over as chief executive in 1981.

Yesterday, Riedy was named president of the J.E. Robert Companies, one of the country's leading managers of troubled real estate properties.

Both Cahouet and Maxwell took pains yesterday to stress that Cahouet was leaving not because of any dissatisfaction with Fannie Mae, but for the opportunity to head the country's 12th-largest bank holding company.

"The reason I am {leaving} is the challenge," Cahouet said in an interview. "To step in as the CEO and help them work out their difficulties is a great challenge." He termed his relations with Maxwell excellent and said Fannie Mae's chief allowed him great latitude in running the company.