Dancer Mikhail Baryshnikov said last night that he was taking an immediate leave of absence of several months from the New York City Ballet, in order to rest an injured leg.

The ballet superstar, 31, reached by telephone in New York, denied that he had been unhappy dancing with the New York company, and said he had discussed his move with NYCB's co-founder and ballet master George Balanchine.

Balanchine, who is in Washington with his ballet company, said last night, "He didn't tell me anything."

"What means to go or stay?" Balanchine added. Speaking of all his dancers, he said, "They can go any time they want."

Baryshnikov was slated in any case to rejoin American Ballet Theatre as its new artistic director in the fall of 1980.

Baryshnikov, who is called Misha by his friends, said he was making the present announcement partly to quell rumors that he had severed all connection with the New York City Ballet.

One source close to the dancer, however, continued to say that Baryshnikov had indeed quit NYCB for good. This source pointed out that while Baryshnikov had canceled his New York performances, he would honor several other dance commitments, beginning with one in Louisville today. h

Baryshinkov last night insisted, "I am not saying that I am leaving the company. I am taking a few months off. I am simply following the advice of my private doctors, who have told me that due to a professional injury I suffered some months ago, it would be dangerous for me to continue dancing right now. It happens that after the beginning of November, I have no obligations to any company until my commitment to ABT next September. And I have fully discussed this with Mr. Balanchine and Mr. (Jerome) Robbins."

The Russian-born dancer was insistent that his present move had not been caused by any alleged disaffection with the New York City Ballet. "It has nothing to do with these rumors of my 'unhappiness' with the company or with Mr. Balanchine, or any such nonsense," he stated. Baryshnikov had nothing but good words for his association with the NYCB, which began in the summer of 1978 at saratoga Springs, N.Y., and has continued through a period which saw him mastering over 20 roles in ballets by Balanchine and Robbins.

"I am more than happy to be with this company," he said, "and it was and is a wonderful experience for me I like the people of the company, the partners I have danced with, the parts which I have danced -- I feel at home in this company and I hope to continue my relationship, any kind of relationship, with it. I learned a lot of things, and I will learn more."

Considering Baryshnikov's withdrawal from the forthcoming New York season in a philosophical manner, Balanchine said that there "wouldn't have been much work" for Baryshnikov anyway, considering the dancer's injury and NYCB's upcoming repertoire.

"You come and your go, why should people stay in one place all the time?" Balanchine asked. "You have children and the children tell you, 'Poppa, we want to go someplace and get married.' You're not disappointed, you tell them, 'Go.' A mother's love is a selfish love -- I am not like that."

Speaking of the remainder of the Washington season, Balanchine said that for Baryshnikov, "There is nothing left to dance. He told me he could not dance on this [Kennedy Center] floor . . . it hurt his foot."

Balanchine said that after Baryshnikov complained about the extremely hard floor on the stage of the Kennedy Center Opera House, he released Baryshnikov from the rest of the Washington engagement.

His last role was opposite Allegra Ken in Balanchines's "La Sonnambula" this past Friday at the Kennedy Center Opera House.

Asked if he would allow Baryshnikov to dance with the company in the future, Balanchine said, "Why not?"

Baryshnikov himself noted that his activities "will depend on my physical condition after these few months of treatment and rest." "Thereafter," he said, "I will make up my own mind when and where I should dance." The question of any future appearances of his with the NYCB beyond this point, he said, would be "my business and Mr. Balanchine's."

Baryshnikov emphasized that he was not incapacitated. "I'm not an invalid," he said. "I'm not limping. I can dance."

Though Baryshnikov may not be dancing at the Kennedy Center again for some time, the production of "the Nutcracker" which he staged for ABT in 1976 (and which had its world premiere here) will be returning to Washington this December when that company arrives for a four-week engagement. It was with ABT that Baryshnikov first danced in this country after his defection from the Soviet Kirov Ballet in 1974, and he stayed with the troupe as a principal dancer until the spring of 1978, when he announced his transfer to the NYCB.