National Public Radio and the Corporation for Public Broadcasting announced a loan agreement yesterday that will save the ailing public radio network from bankruptcy and keep its national programming on the air.

In the agreement, CPB next week will give the radio network a line of credit up to $8.5 million and forgive a debt of $600,000 for a total of $9.1 million--the amount of the deficit NPR expects to have for fiscal 1983.

Also, CPB agreed to give NPR an immediate advance of $500,000 from the $1 million monthly federal payment due Monday. NPR needed the money to meet its payroll for 300 employes today.

The agreement, which followed days of public feuding and private infighting by CPB and NPR, took the form of a letter of intent to reach final terms by Tuesday.

"This is a most creative and fiscally prudent solution," said Sharon Percy Rockefeller, board chairman of CPB, the independent agency that distributes federal money to public radio and television.

Negotiations over the lifesaving, three-year loan had reached a standstill when members of Congress, including Rep. Timothy E. Wirth (D-Colo.), Rep. William H. Natcher (D-Ky.) and Sen. William Proxmire (D-Wis.), demanded Wednesday that the two sides find an agreement that would keep the network alive.

The ensuing talks lasted 12 hours and ended at 4:30 a.m. yesterday.

"The negotiations were difficult indeed," said Donald Mullally, interim chairman of the NPR board.

The fight centered on CPB's demand that NPR relinquish title to satellite transmission equipment as collateral for the loan in order to protect the equipment from creditors in case of bankruptcy.

Inside NPR this proposal was viewed as a restructuring and decentralizing of the network.

Under the agreement, NPR will transfer the equipment to a 3-person trustee group, rather than the public radio stations CPB had chosen.

Said Mullally, "Although it is restructuring to some degree, it is not pernicious."

Though NPR and CPB would not comment publicly, sources at CPB said the members of the trust would be Elliot L. Richardson, an attorney who has held four Cabinet posts and has served as ambassador to Great Britain; Henry Geller, former general counsel of the Federal Communications Commission and head of Duke University's Washington Center for Public Policy Research, and Virginia Duncan, a former member of the CPB board, who is now with the Bechtel Group Inc. of San Francisco.

The decisions of the trustees will be subject to approval by a majority of the 281 NPR member stations.

Yesterday's actions came at the end of five dramatic months of revelations about NPR's financial difficulties, questions of mismanagement, cutbacks of staff and programs, firings of top management and congressional inquiry into NPR's internal operations.

Soon after the deficit problems were first announced in March, Frank Mankiewicz, NPR's president for almost six years, resigned. Under Mankiewicz's management, the network had almost tripled its budget and doubled its listenership to almost 9 million. Its signature news magazine programs, "All Things Considered" and "Morning Edition," had won many prestigious awards.

An independent audit of the network by Coopers & Lybrand, released in June, found that NPR had more than $5 million in past-due bills, including payroll withholding taxes and money owed to American Express, Chesapeake and Potomac Telephone Co., Western Union and Oliver Carr, who owns the NPR headquarters building here. An interim managment team cut the fiscal 1984 budget from $26 million to $17.65.

A number of powerful congressmen, including Rep. John D. Dingell (D-Mich.), had worried that the crisis at NPR would damage the reputation of public broadcasting in general. Dingell, who has fought for increased appropriations to public broadcasting, has requested an audit of NPR by the General Accounting Office and has spoken of the "strong possibility" of public hearings.

When Rockefeller was asked yesterday what the causes of the financial debacle were, she said, "I am satisfied that I know extremely well what happened here. Those questions will be taken up in the public forum of the House and Senate, probably in September."

Though officials from both CPB and NPR met with congressional members Wednesday, Rockefeller said they "did not advise us as to what course to take. They said it was best for public broadcasting to solve the problem."

Solutions to immediate problems may have started yesterday, but questions have been raised about a future satellite deal NPR has entered into with National Information Utility Corp. of McLean. The venture partner has almost no money on hand, according to papers at the Securities and Exchange Commission.

Ronald C. Bornstein, acting chief operating officer at NPR, said yesterday the announcement of the business partnership, which said NPR would receive $5.5 million, emphasized "the potential of the company." Asked if the deal was still viable, Bornstein said, "I really can't make a judgment."

The loan agreement is contingent on the signed guarantees of a majority of NPR's 281 member stations. CPB president Edward Pfister said CPB had received 170 agreements.

Since the first of the year, 140 employes at NPR have been sacked. Though he didn't promise that any jobs would be restored, Bornstein was cautiously optimistic about restoring programming that has been cut.

"The Sunday Show," a weekly magazine program, and the news portions of a daily information and cultural package, "NPR Plus," have been cut, and "Jazz Alive" was due to be eliminated Oct. 1.