Robert S. McNamara retired yesterday from the presidency of the World Bank after 13 years as the head of the 139-nation development institution.

In a ceremony, he handed the key of the bank building to his successor, A.W. Clausen, former head of Bank of America, the second-largest commercial bank in the world.

Under McNamara's presidency, the bank's lending to poorer nations of the world has expanded enormously from $1 billion to over $13 billion a year, most of which is made on commercial terms and financed by raising capital in world markets.

This makes it the largest development agency in the world, providing assistance to countries with a combined population of some 3.5 billion people, according to a release from the bank yesterday.

McNamara said in a farewell message to the staff yesterday that the bank "has grown into one of the world's most constructive instruments of human aspiration and progress." But he added that it "has only barely begun to develop its full potential. . . . There is so much more it can do, so much more it ought to do, to assist those who need its help."

McNamara is leaving at a time when the bank is under increasing pressure to curb the expansion of its lending, which he believes is essential for the well-being of the world economy. The Reagan administration does not share his commitment to expansion. Previous administrations and Congress have also often been unwilling to give more money to the bank.

McNamara has been a staunch supporter of projects aimed at helping the very poorest in the developing nations, and this emphasis may change with his departure. The 65-year-old outgoing president made his public farewell in an emotional speech to the joint annual meeting of the World Bank and the International Monetary Fund last fall. He called then for a change in the very conservative rules governing bank lending to allow increased lending with no additional capital, and to set up a new energy affiliate to encourage energy production in the developing world.

Both issues are left for Clausen to deal with. The Reagan administration, which is generally unsympathetic to multilateral aid and has criticized the World Bank for encouraging public rather than private-sector projects overseas, has refused to support the new affiliate so far.

Another pressing problem for Clausen is Congress' refusal so far to provide new funds, already agreed on in principle, for the International Development Association, the arm of the bank that makes concessionary loans to the poorest nations in the world. In last week's budget vote, the House cut U.S. payments to IDA in half.

Since other countries' contributions to this fund are computed on the basis of how much the United States gives, "it would require a complete renegotiation of the agreement under which the other governments are committed to provide funds" if the House vote stands, McNamara said in an interview this week with the Associated Press.

McNamara lamented the U.S. attitude to foreign aid as a low-priority budget item. Aid expenditures are very much in the U.S. interest, he said in the interview, as "one-third of our trade is with the developing world."

He stressed the strategic importance of a reduction in aid, saying "if they have economic disorder, it translates into political disorder, and political disorder in various parts of the world overflows and affects us strategically."

He has accepted several appointments to the boards of nonprofit institutions and major corporations, including The Washington Post Company. In his farewell to bank staff, McNamara called his years at the bank the best of his life.