WASHINGTON, Oct. 13— The Government said today that it had agreed to grant a tax exemption to the Church of Scientology and more than 150 of its related corporations, ending one of the longest-running tax disputes in American history.

“This puts an end to what has been an historic war,” said Marty Rathbun, president of a Scientology organization that received a tax exemption. “It’s like the Palestinians and the Israelis shaking hands.”

Officials at the Internal Revenue Service and the Scientology group declined to spell out the details of the settlement and would not explain why it had finally been reached after four decades of costly and bitter court fights.

People familiar with the group’s closely held finances said the tax exemptions could save the organization at least tens of millions of dollars a year in taxes.

The exemptions were granted as part of a larger settlement between the Government and the Scientology organizations that ends legal disputes that go back to the founding of the church 39 years ago. Church officials said the settlement would close more than a dozen lawsuits.

Officials at the Internal Revenue Service said the decision granting the Scientologists tax-exempt status does not change the standards for determining when an institution is to be considered religious for tax purposes. They also said that the ruling would not affect how other groups are treated.

But some tax lawyers who have advised organizations seeking tax-exempt status said the ruling would make it easier for them to argue their cases.

The church’s California branch had a Federal tax exemption at one point but lost it 26 years ago, and most of the other related organizations never had exemptions. For decades, the Government has said that although Scientology can be considered a religion, its affiliated organizations had operated as businesses for the financial gain of the church’s leaders, most notably L. Ron Hubbard.

Mr. Hubbard, who founded the group in the 1950’s after his book “Dianetics” became a best seller, responded to the Internal Revenue Service’s challenge by making anti-Government statements that became part of the church’s dogma. And after Mr. Hubbard died in 1986, other Scientology leaders, including its top official, David Miscavige, continued to preach against the Government and the tax collectors. Charitable and Religious

But today, Frank Keith, a spokesman for the Internal Revenue Service, said that as part of the settlement the Government had decided to classify the sprawling empire as a charitable and religious organization.

Mr. Keith said the group was notified of the decision on Oct. 1 and that it followed a two-year review of financial statements and other information provided by the organizations about their structure and purposes. He would not say whether the final decision had been made by the new Commissioner of the Internal Revenue Service, Margaret M. Richardson, who would normally have to approve any large settlement.

The ruling means that the church and more than 150 related educational and counseling groups will no longer have to pay Federal income taxes. Church members may also deduct their membership dues from their taxes. Mr. Rathbun said that the groups did not expect to receive refunds of back taxes because they had not been assessed for many of the years that they were contending to be a religious organization.

Conciliatory Tone

Mr. Rathbun was unusually conciliatory toward the I.R.S. today. He said the church had prevailed after what he called “an objective review” under the auspices of John Burke, an assistant commissioner who heads the agency’s Employee Plans and Exempt Organizations division.

The Church of Scientology has branches around the world and has its headquarters in Los Angeles. It calls itself a “new religion,” one not based on the worship of a god, but rather one that purports to teach members how to improve the quality of their lives. Instead of salvation, it promises to rid the mind of mental obstacles to happiness and help members improve the world.

But some courts and many former members have called the organization a sham, saying it relies on religious pretenses to mask a highly profitable business. Membership in Dispute

The group claims a membership of eight million, although former members say that those figures are grossly inflated and that the total is probably closer to 50,000.

The Federal Government recognized the Church of Scientology of California as a tax-exempt religious organization in 1957, but revoked that exemption in 1967. Its decision led to a wave of litigation by the church and the Government over various issues, like the church’s request under the Freedom of Information Act for Government files, to the Government’s attempts to assess the organization.

In 1984, a Tax Court concluded that the church had “made a business out of selling religion,” and that Mr. Hubbard and his family had diverted millions of dollars of church funds. And a Los Angeles Superior Court judge called Mr. Hubbard “a pathological liar” who seemed gripped by “egotism, greed, avarice, lust for power and vindictiveness and aggressiveness against persons perceived by him to be disloyal or hostile.”

Court documents showed that the church had an extensive project to infiltrate Government agencies in the United States and more than 30 countries to suppress investigations of the organization. Ultimately, 11 church leaders, including Mr. Hubbard’s wife, Mary Sue, served prison terms for the wiretap of an Internal Revenue Service office and other crimes.