Ireland's biggest bank signed an agreement yesterday to take over First Maryland Bancorp, the holding company for First National Bank of Maryland.

It is the second time in less than two years that a major bank in the Washington area has been taken over by foreign interests.

Under terms of the agreement signed yesterday, Allied Irish Banks Ltd. of Dublin will acquire about 43 percent of the $3.4 billion Baltimore bank company by the end of the year. During the next four years, Allied Irish would increase its interest in First Maryland Bancorp to between 50 percent and 60 percent.

Terms of the transaction call for Allied Irish to pay $95 million for the 43 percent stake in First Maryland and to invest upwards of $35 million more to buy full control of the bank.

First National Bank of Maryland is the second largest bank in the state. It would become the second major foreign-owned banking institution in the Baltimore-Washington-Richmond corridor. The Washington-based First American banks were taken over last March by a group of investors from the Middle East.

Unlike the acquisition of First American, which began as a hostile takeover, the transaction between Allied and First Maryland Bancorp is a friendly agreement.

Allied Irish, which has assets exceeding $8 billion, plans to make Maryland the home state for its U.S. operations if the plans to acquire First Maryland Bancorp are approved by regulatory authorities and First Maryland stockholders. Allied Irish already operates branches in New York and Chicago.

Allied Irish's investment will be made through a combination of purchases from First Maryland stockholders and new shares to be issued by First Maryland.

Allied Irish plans to make a tender offer this year to acquire 1.8 million shares at $35 each from First Maryland stockholders.

Before the end of the year, First Maryland, which has about 5.2 million shares outstanding, will issue 800,000 new shares to Allied Irish at $40 each--giving the Irish investors 43 percent of the outstanding shares.

In addition, First Maryland will sell Allied Irish one million new shares over a four-year period at prices between 100 percent and 115 percent of book value.

The tender offer is expected to be completed by the end of this summer. If completion of the tender offer is delayed until after March 1984, the price that Allied Irish pays for the stock will be adjusted to reflect changes in First Maryland's book value at the end of 1983.

If Allied Irish receives approval from government regulators to buy only a 25 percent interest in First Maryland, the remainder of its stock will be held as a nonvoting interest.

A spokesman for First Maryland said directors approved the agreement because the price that Allied Irish has agreed to pay for the stock is attractive in the current market. In over-the-counter trading yesterday, 16,800 shares of First Maryland moved, closing at $28, up 2 1/4.

And in a prepared statement yesterday, First Maryland Bancorp Chairman J. Owen Cole noted that one of the most important advantages of the transaction is the "infusion of over $80 million in additional equity capital."

The agreement surprised the banking industry in the region, but it had begun to take shape as early six months ago when Allied Irish first contacted First Maryland about a possible partnership.

After an extensive study of banks in various states, Allied Irish narrowed its focus to Baltimore and First Maryland, said Jerry Casey, executive vice president in charge of the Dublin company's North American operations.

First Maryland Bancorp satisfied all the criteria of a strong regional bank, Casey said. "We were impressed with the demographics of Maryland and Baltimore," he added.

Allied Irish operates a merchant bank and finance company in Ireland. Its bank ranks 189th among the top 500 in the world. Last year the company reported $55 million in after-tax profits and a pretax profit of $85 million.

Allied Irish opened its first U.S. branch in New York in 1978 and a second in Chicago the following year. Its total North American assets are about $500 million.