Health and Human Services Secretary Margaret Heckler and her estranged husband John Heckler today agreed to an out-of-court settlement in their four-week-old divorce trial, ending a marriage that began in New York's St. Patrick's Cathedral 31 years ago. The grounds for the divorce were downgraded from "cruel and abusive" treatment to "irretrievable breakdown" of the marriage, a no-fault arrangement.

The trial that had initially been expected to produce fireworks instead sputtered along with day after day of financial testimony and ended not with a bang but with the rustling of legal briefs. At 6:50 this evening both Hecklers faced each other like weary prizefighters for the final round. Both claimed victory.

After the pronouncement by Probate Court Judge Edmund V. Keville approving the terms of the settlement, the Hecklers approached each other and shook hands. "I wish you well," Margaret Heckler told her husband. "Thank you, dear," John Heckler replied.

Both parties declined to discuss details of the settlement, which reportedly consists of an even split of the couple's joint property as well as a cash settlement for Margaret Heckler of between $750,000 and $1 million. The divorce will become final in nine months.

"I just have to say that I'm very happy that it's over -- there are no winners in a case like this. I'm pleased and I look forward to a whole new life," said the 57-year-old John Heckler.

Margaret Heckler, 53, sounded equally relieved. "I have mixed emotions. It's a time of sadness . . . there's been a lot of stress here, a lot of pain. John has felt it, I've felt it, our children have felt it. It's time to put the past behind us. I really have no bitterness here. A marriage that produced such beautiful children is nothing to be sorry for. There have been many, many beautiful experiences in our lives together. Now it's time to go on."

The Hecklers have three children, a son, 24, and two daughters, 25 and 27.

Lawyers for both sides had met into the early-morning hours for the past three days, trying to divide the Hecklers' assets, which include a condominium overlooking the Potomac River in Rosslyn and a colonial house in Wellesley, Mass.

In some ways the case of Margaret Mary O'Shaughnessy Heckler v. John Maguire Heckler was no different than dozens of other domestic dramas unraveling in the hallways of Dedham Probate Court. Except that it was occurring in the courthouse adjacent to the political district where Margaret Heckler began her career. Each day there were political friends in the courtroom as well as local reporters who could remember writing profiles of the Heckler family when she was first elected to the U.S. House of Representatives in 1966.

John Heckler first filed for divorce in Virginia two years ago, accusing his wife of "desertion and abandonment" of their marriage. That claim was dismissed because his legal residence was in Massachusetts at the time. He and his wife both subsequently filed for divorce in Massachusetts, each accusing the other of "cruel and abusive" treatment.

In opening statements over a month ago, John Heckler's lawyers had titillated the courtroom with the claim that Margaret Heckler had not engaged in marital relations with her husband since 1963, condemning him, lawyers said, to a life of "celibacy or adultery." The opening statement also included an admission of John Heckler's adultery.

In interviews before and during the trial, John Heckler portrayed himself as the dedicated political spouse, a strategist who had managed his wife's early political career and campaigns, only to find himself as the years went on playing second fiddle to politics. He charged that the union was a marriage in name only that survived only because his wife believed a divorce would hurt her career.

Margaret Heckler was elected to Congress in 1966 after holding statewide offices in Massachusetts. She moved to Washington with her three young children. Her husband remained in Massachusetts and commuted to Washington on weekends. A Roman Catholic, she has said that she long believed problems with the marriage could be worked out without divorce. Throughout the trial, she has declined to comment on her husband's version of events, in part because of her Cabinet position.

The central issue in the trial was the value of John Heckler's share of the investment banking firm he founded in 1970. Margaret Heckler sought a share of that company, which reported sales of $9 million last year. Her expert witnesses stated its value to be $4.8 million. John Heckler said his share was worth no more than $1.3 million. Margaret Heckler, who never testified, had contended that she had helped build the business, and so was entitled to a share of it.

John Heckler had also estimated the worth of her federal pension at over $400,000, more than three times the value her lawyers had given it. Margaret Heckler, a former eight-term Republican congresswoman, became a member of the Reagan Cabinet two years ago and lives in the couple's $318,000 Rosslyn condominum. She said today that her husband will sell the couple's three-story 19th-century colonial house in Wellesley, where he has been living.