The refurbished battleship Iowa and six sister ships will be based in New York City, Secretary of the Navy John F. Lehman Jr. announced yesterday, bringing with them 3,600 military personnel and their families and an annual payroll of $72 million.

The announcement ends eight months of seduction, cajolery and political pressure by Boston, Newport, R.I., and New York City, each of which energetically sought to become home port to the new seven-ship surface action group, which Lehman said would pump $500 million into the New York economy.

The decision, which Boston officials had been told on Wednesday would come "within three weeks," took officials in all three cities by surprise. New York City Mayor Edward I. Koch learned of it early yesterday morning, just before it was announced at a breakfast meeting on the carrier Intrepid.

"In terms of dollars," Koch told a morning news conference, "it's terrific. It means jobs. It means the Navy has come home to New York City." Sen. Alfonse M. D'Amato (R-N.Y.) said the decision "is like bringing the Brooklyn Dodgers back home."

The ships will bring with them 3,600 permanent jobs, 400 of those civilian, and create 1,500 temporary construction jobs while the Navy spends $103 million to turn the chosen site in Stapleton, Staten Island, into a suitable berthing facility.

The boost the port was expected to give to the local econony led to an extraordinary effort by all three cities to persuade the Navy of the suitability of their areas. Congressional delegations, governors, mayors and chambers of commerce were all enlisted in preparing proposals, writing letters and meeting officials.

Boston officials even commissioned an outside engineering firm, Stone & Webster Inc., to do an independent study which concluded that Boston was the best location for basing the ships.

The Navy said nine factors were evaluated in making the decision on where to base the ships: ship movement and berthing, housing, utilities, ship services, base and personnel support, land, quality of life, operational considerations and cost.

Officials in the spurned cities were irritated. Both the chairman of the Boston Chamber of Commerce and the mayor of Newport learned of the Navy's choice from the radio.

Newport Mayor Paul L. Gaines said in a prepared statement, "I am surprised over the fact that New York was chosen over Boston or Rhode Island, both of which are strategically better than New York. I hope the decision was made strategically rather than politically." Rhode Island and Boston are closer to Europe than is New York.

Speaker of the House Thomas P. (Tip) O'Neill Jr. (D-Mass.), who lobbied hard to have the ships based in Boston, demanded a full accounting of how the decision was made.

The Navy has promised to release within two weeks the report weighing the merits of the three ports and detailing the reasons for selecting New York City. Before work can begin on the port, the Navy must do an environmental impact study to determine the effect of basing the ships in New York's harbor will be on human and natural ecology.

That study is expected to take a year. Navy officials hope to have construction money in the fiscal year 1986 budget and the first ships tied up in 1988.

Officials in Boston, who asked not to be identified, said that Boston had been the most expensive site, with New York second and Newport third. The statement from Boston Mayor Kevin H. White was mild, in the hope, said one official, "that if the impact statements on Staten Island don't pan out, Boston still might be chosen."

The stationing of ships in the New York area is part of the Navy's "strategic dispersal of forces," in which ships from the fleet are being spread more thinly along the coasts in an effort "to improve our defensive posture," according to Navy spokesman Lt. Tom Yeager.

The Navy declines to say which ships carry nuclear weapons, but it has been assumed that at least some of the seven ships in the Iowa group will be armed with nuclear-tipped cruise missiles. There has been some anxiety among officials about the reaction in the Northeast from anti-nuclear groups to basing of the group in the area.

But yesterday Koch, flushed with his city's victory, said, "My own belief is that there is no danger," adding later that he thinks the Navy "has the security of the American people as its top priority."