Barely two hours before he was to have been deported yesterday, Ramchandra Malekar, the Indian who wants to marry an American girl, won an injunction from a U.S. District Court judge barring immigration officials from placing him on a connecting flight to India.

Judge Roszel Thomsen in Baltimore handed down the temporary restraining order - effective for 10 days to give Malekar's friends time to win support from Congress for their efforts to halt the deportation - while Malekar, guarded by an Immigration and Naturalization Service officer, sat in a waiting room at Baltimore-Washington International Airport.

The 11th-hour victory for Malekar, who was represented in the Baltimore courtroom by an attorney retained by American friends, followed the young Indian's release earlier yesterday from prison, where he had just completed serving time for a manslaughter conviction.

His friends had attempted to delay his release in hopes that when the Senate reconvenes on Feb. 21, U.S. Sen. Charles McC. Mathias (R-Md.) would introduce a bill enabling Malekar to remain in the United States.

It was partly because of the fact that Mathias is considering aiding Malekar that Judge Thomsen decided to issue the temporary restraining order, which he can extend for another 10 days if he wishes.

"I've been crying all morning," said Rosie Wolff, who thought at the time Malekar, her fiance, was about to be deported halfway around the world. But when she learned at 1:30 yesterday afternoon of Judge Thomsen's ruling, she started crying all over again with happiness.

"Boy, I tell you, if there ever was a miracle, it was this," she said.

When news reached other friends of Malekar around Hagerstown, Md., they were ecstatic. "Was this down to the wire, or was this down to the wire?" laughed Robert Charlesworth, manager of the Fountain Head Country Club where Malekar worked while participating in the prison's work-release program.

Charlesworth and many others have been working for months now trying to keep Malekar from being deported. "God dern, I'm happy. We haven't had time to break out the champagne yet, but any minute we will."

By 2:30 p.m., however, Ramchandra Malekar still did not know what had happened. He sat in the C-7 waiting area of Baltimore-Washington airport, waiting to board the 3:10 flight that would take him to New York and then on, for two long days, to India. Wearing a cheap new flight jacket, he stared out the windows wearily.

An immigration officer with a waxed mustache stood at his side but no word had yet been spoken to him about the temporary reprieve. It wasn't until a reporter told him that he would be going to the Baltimore Jail instead of India, and that Sen. Mathias was now considering signing a "bill of relief" to allow him to live in this country, that Malekar learned of the temporary reprieve.

"How I know?" he asked quietly, disbelieving. When finally he was convinced, he smiled broadly for a moment, then the bright expression faded away. His fate is still far from certain. It was only the first step. "That's good. I . . . can't express how I feel. I want to make a new life here. I want happy new future in this country," he said.

When he was brought to Bethesda from the streets of Bombay in 1973, Malekar spoke no English at all. He was paid virtually nothing by his new employers, Mohan and Lalita Khambadkone, though his life was more comfortable than it had been in India.

Then, just over four years ago, he killed Mrs. Khambadkone. The circumstances of her death are still unclear because Malekar was the only witness and the language barrier posed by his Marathi dialect was difficult to overcome. The cause of Lalita Khambadkone's death, however was listed as strangulation.

In prison Malekar began rebuilding his life. He was soon allowed on work release and home release programs and won the friendship of many people he met in the Hagerstown area, including Rosie Wolff, who he hopes to marry. These friends claim he is totally rehabilitated, that that they will sponsor him, give him a job, and they have fought hard to keep him here.

The law in Malekar's case, however, is "flat," in the words of Judge Thomsen. It states flatly that any alien in the United States will be deported if convicted of a felony here.

The order for his deportation dates back to Nov. 6, 1975. At the time Malekar's legal aid attorney waived his appeal of the order.

Malekar and his friends have hoped that this could be overruled by a "bill of relief" filed in Congress. They were in touch, over the last year, with several representatives from Maryland, and were told by at least one that the bill would be considered. By last month, however, it was clear to them that it would not be filed.

Ten days ago they approached Sen. Mathias, and he said he would consider introducing it. They showed him a petition backing Malekar and signed by 150 members of the Fountain Head Country Club, as well as numerous affidavits on his behalf.

According to a spokesman, Mathias thought Malekar would not be released to immigration authorities until Feb. 21, which would have given him time to consider all the facts and file the bill when the Senate reconvenes.

It was decided by prison officials, however, that several days would be taken off Malekar's sentence for "good behavior." As a result time seemed to have run out, and many of Malekar's friends gave up hope before yesterday's last minute ruling.

Mathias's spokesman, John W. Eddinger, says that even though the senator now has "a chance to look at the case completely and dispassionately" there is "no guarantee" that he will introduce the bill.

Malekar did not have time to think about all of this as state troopers and more immgration officials came into the airport waiting room. He seemed confused and subdued as he was hustled away into a waiting squad car for the trip to Baltimore jail.

A reporter asked him if he had any word for Rosie Wolff. A smile lit his face again. "Oh sure!" he said, disappearing down a ramp before he could finish.

But that morning, when he said goodbye to her at the Hagerstown prison, he had told her yet again that he loved her. His parting words were, "I'll be back."