A three-way contest to gain control of the country's first federally chartered women's bank ended yesterday when Leo M. Bernstein, chairman of Security National Bank, agreed to buy an interest in First WNB Corp., the holding company for Women's National Bank.

First WNB Corp. issued a brief statement confirming that it had accepted Bernstein's offer, which is contingent upon regulatory approval. The purchase would also require satisfactory completion of a "due diligence review" by Bernstein, First WNB said.

Bernstein, a wealthy investor who has held either controlling interest or substantial shares in several Washington banks, would only confirm that he has reached an agreement with WNB. Neither First WNB nor Bernstein would say what percentage of the company's stock he has agreed to buy.

Bernstein has until May 13 to conclude a review of First WNB and may withdraw his offer at any time during the interim. The agreement calls for Bernstein to make a tender offer to First WNB shareholders by June 30, unless he receives an extension.

First WNB had been the object of considerable interest by prospective buyers in recent weeks. Directors of the corporation rejected an offer earlier this week from National Bank of Washington. A third suitor was not identified.

Women's National, which has deposits of $12.2 million, opened in 1978 as the first federally chartered financial institution in the United States to be controlled by women. It had operated only one banking office until last year when it opened branches in Georgetown and on Capitol Hill, prime locations which made it attractive to prospective buyers.

Profits at Women's National more than tripled two years ago but the bank reported a net loss of $231,000 in 1982. Bank officials attributed the loss to an increase in bad loans, mainly in real estate, and to costs associated with the opening of the two branches.

After five years of uneven results and last year's loss, Women's National said earlier this year that it would be difficult to turn a profit in 1983.

Banking sources said directors of First WNB had become concerned about the bank's direction in recent months. The same sources said that First WNB had sought a merger after being unable to find a replacement for the bank's chief executive officer, Emily Womach, who recently resigned for health reasons.