First Lady Nancy Reagan was the toast of Broadway tonight in a show biz tribute to her old friend Mary Martin that brought down the house.

"I'm a little out of my element," Mrs. Reagan told a sellout crowd in the Shubert Theatre, as Mary Martin stood beside her. "I really don't go around the White House singing."

She could have fooled her audience, a star-studded assemblage of entertainment world figures, many of them, like her, taking their turn on the stage.

In a clear if sometimes quavering voice, Mrs. Reagan sang a tune from "Lute Song," the 1946 Broadway musical starring Mary Martin. The show's cast included an aspiring actress named Nancy Davis. In a bit part she portrayed a character called Tsi-chun. The show ran for 142 performances and was her last appearance on Broadway.

Describing it all tonight, she remembers how she had been "so thrilled" to be on Broadway with Mary -- "to be with Mary Martin was frosting on the cake."

Tonight -- 39 years later -- was more frosting for Mrs. Reagan, who said she had been "so happy" to be part of the evening "for this very deserving lady who could teach us all about professionalism and courage in the face of adversity."

The number she sang, she said, she had chosen because it always reminded of her old friend and tonight it seemed especially appropriate.

"If you need me I will be nearby," the lyrics began, "mountain high, valley low . . . My love follows you until the last, lightning fast, turtle slow . . ."

Near the end of the refrain Martin joined her, their arms around each other in a show of affection.

But for nearly two dozen others saluting the 72-year old musical comedy star, it was also frosting on the cake.

Helen Hayes told of appearing with Martin in Paris some years back and described how they were walking the Champs E'lyss'e one day. Martin was wearing a new Mainbocher outfit.

"A bird came down, went swoosh, and Mary was covered," said Hayes. "I was very frightened about what she'd do, but she just turned and said, 'For some people they sing.' I loved her from that moment on."

Some, like Joshua Logan, brought poems written in Martin's honor. Others, like Jerry Herman, who gave the world "Hello, Dolly!," simply rewrote lyrics she had made famous. With Herman on the piano and Carol Channing belting them out, the words to "My Heart Belongs to Daddy"took on new meaning. She sang: "She played a nurse, she played a nun, she played a boy who was a fairy. She stopped the show when she had to crow and our hearts belong to Mary."

For most of the evening she sat in Nancy Reagan's box, a not always quiet figure watching her friends parade moments of her life before her in song and verse. They called the tribute "Our Hearts Belong to Mary," after her 1938 Broadway hit which sent her on the road to stardom.

Robert Preston, her costar in "I Do! I Do!," told how he had been a very successful bigamist in 1966. I had one wife in Connecticut and the other in a 46th Street theater. He sang "My Cup Runneth Over," and from the darkened theater box echoed "with love."

George Abbott was there, as was Lillian Gish. She went on stage to tell Martin she had been sitting in the fourth row that night when she first sang "My Heart Belongs to Daddy" and recognized her talent as something special.

"I was there and you sang just to me," Gish told the audience. "I said she's got the three Ts -- taste, talent and temerity."

New York Mayor Edward Koch showed up, self-cast as a Lochinvar, when he said he remembered Martin in "South Pacific" as a young girl loved by an elderly man.

"I was thinking to myself out there tonight, if I had a voice, I could play that elderly man," said Koch.

He just happened to bring along a copy of his book, "Mayor," slipping it into Nancy Reagan's hands about the same time he gave her a kiss. In a more serious vein, a few minutes earlier, he said he wanted her to convey to the president "how proud we are of what he recently did."

There were others saluting Martin -- Maria von Trapp, on whose life "The Sound of Music" is based; Don Correia and Sandy Duncan, who did a tap routine of "Honey Bun," and Van Johnson, whose way was paved for him in Hollywood by Martin.

"I just can't believe this night is happening," Martin said as one entertainer after another sang her praises. "Too much of that can go to your head."

The benefit program included Martin singing a duet with her daughter, Heller Halliday DeMerritt, the Whiffenpoofs choral group, the U.S. Naval Academy chorus singing "There Is Nothing Like a Dame."

Other participants included Dorothy Rodgers, Dorothy Hammerstein and John Raitt.

Martin's son, actor Larry Hagman, had been scheduled to appear, but was detained on the "Dallas" set and sent a filmed message to his mother instead.

Mrs. Reagan and Martin rehearsed together in person for the first time this afternoon. The show's producer, Anna Sosenko, said they got their act together by long-distance telephone.

"They got on the phone with a pianist playing for them and rehearsed that way," said Sosenko. They also sang onto tapes and sent them to each other.

The veteran Broadway producer said she first discussed the tribute with Martin in London a few months ago. "She loved it and said, 'You know what would be great is if we could get Nancy.' "

Back in New York, Sosenko wrote to Mrs. Reagan, who responded right away. Sosenko said the first lady herself came up with the idea of what to do in the show.

It was almost too much to hope for that the first lady would actually sing in the show, so Sosenko didn't ask her to do it -- "I didn't dare. But as it turned out, she suggested that maybe she should do something with Mary from 'Lute Song.' "

For tonight's tribute Sosenko brought together some of the biggest names in the business to help her. Donald Saddler staged it, and William Harbach was the creative consultant. An estimated $175,000 in proceeds from the evening, including a gala supper afterward at the new Marriott Marquis Hotel, are going to the Theater Collection of the Museum of the City of New York. Benefit chairmen were Dorothy Rodgers and Dorothy Hammerstein; cochairmen were Donald Brooks, Patricia Kennedy Lawford, Liz Smith and Geraldine Stutz.