The Federal National Mortgage Association (Fannie Mae) yesterday reported third-quarter profits of $22.7 million (31 cents a share), making it the company's most profitable quarter in two years.

That compares with a $43.1 million loss during the third quarter of 1984.

"We are extremely pleased with the corporation's third-quarter performance," said Fannie Mae chairman and chief executive David O. Maxwell, who credited lower interest rates for much of the performance improvement.

Fannie Mae, a congressionally chartered, privately owned corporation, buys mortgages from lenders to provide those lenders with new funds to make additional loans. During the high-interest years of the 1980s, it has been troubled with a large portfolio of old, low-interest loans with yields below Fannie Mae's borrowing costs.

However, Fannie Mae reported that it had increased loan charge-offs to $47.2 million during the third quarter up from $27.6 million last quarter as a reflection of the continuing high rate of foreclosures and the cost of carrying foreclosed properties.

The company increased its provisions for losses to nearly $61 million during this third quarter -- up from $35.4 million last quarter. During the third quarter of 1984, the loan loss provision totaled more than $125.5 million.

For the first nine months of the year, Fannie Mae has had profits of $16.4 million (24 cents). This compares with a loss of $26.2 million, or 40 cents a share, during the same period last year.

*United Virginia Bankshares Inc. yesterday announced that its third-quarter profits climbed 11 percent to $17 million, compared with $15.4 million for the third quarter of 1984.

The bank holding company, whose United Virginia Bank subsidiary has 191 banking locations across Virginia, also said that earnings per share for the quarter were up 8 percent, to $1.35 from $1.25, over the same quarter last year.

For the first nine months of 1985, the bank's net income has increased 18 percent to $50.3 million over the similar 1984 period, while earnings per share totaled $3.99; up 14 percent compared with the first nine months of 1984.

Total loans for the third quarter jumped 16 percent to $4.8 billion over the third quarter of 1984; with commercial loans growing 21 percent to $2.7 billion and installment up 19 percent to $1.2 billion.