BOSTON -- Terence Karamba may be too young to divine the importance of the term ''diplomatic immunity.'' At 9, any boy would find it hard to understand why such words would protect a father but not the son he may have abused.

Terence Karamba would be even more surprised to know that he has become the star of an international tug-of-war, a diplomatic custody fight. Yet the boy from Zimbabwe is just that: the central figure in a dispute before the U.S. Supreme Court that pits the best interests of one child against the interests of the international community in upholding a diplomatic code.

The eldest child of a Zimbabwean diplomat at the United Nations came to notice in the haphazard way that private pain sometimes becomes public information. One morning, it is alleged, he arrived at his Queens, N.Y., school bloody and bruised.

The city charged that his father, Floyd Karamba, ''tied Terence's forearms and legs together with wire and repeatedly struck him with an electrical extension cord.'' During some of these beatings he was, they say, hung from pipes in the basement while his mother and two sisters were made to watch.

The Human Resources Administration, still reeling from the death of 6-year-old Elizabeth Steinberg, allegedly at the hands of her father, gave this boy what they could not give Elizabeth. It gave him safety, a foster home.

Because the father was a diplomat, he was immune from prosecution, but not from expulsion. The State Department ordered him to go home, citing unacceptable conduct. He went, followed by his wife and daughters, while Terence stayed in a foster home in New York.

Then Zimbabwe demanded its young citizen back. Officials there prickled at the implication this boy would be safer in America than in his own country. More to the point, they prickled at a breach of diplomatic rules.

In this dispute, our own government has tried to sound a position at once in sympathy with the child and yet in support of international law. But in fact, the two conflict, and the State Department comes down on the side of diplomacy.

As Tom Merrill, who filed the government's brief with Justice Blackmun on Tuesday, puts it: ''We wouldn't be happy if the officials of another country took a child of an American diplomat and determined that they had the authority to decide the custody of that child, or indeed whether the child had been abused.''

We subscribe to rules precisely so our own diplomats or their children won't be at risk in other countries. There are questions of international law here. But there are also questions of one boy's psyche.

Terence is a fragile and frightened boy, his caretakers say, a boy who has tried to jump out of a car, out of a second-story window. When told in the gentlest terms he might return to Zimbabwe, Terence, they report, crawled into a cardboard box and sat there, rocking back and forth.

So his Legal Aid Society lawyer, Janet Fink, asked Justice Blackmun to rule that Terence can apply for asylum in the United States. ''To us, '' she says, ''this is a children's rights case.''

Yesterday, however, the Supreme Court removed the last barriers to Terence's being returned to Zimbabwe. There was never much chance it would do otherwise. As even Fink admitted at one point, ''What we're asking for essentially is time.'' But this is not a case that had to come to such a hard, unyielding, legal confrontation in the first place.

The charges that filled the air during the last weeks were full of acrimony. The authorities in New York were not ''kidnapping'' Terence, as the Africans claimed. They didn't intend to keep the boy permanently. Nor was Zimbabwe planning, as sometimes charged, to return the boy to his father. The government has one of the most elaborate child welfare programs in Africa. Child abuse is regarded there at least as harshly as it is here.

The best ending to this story would have been a reassuring, careful transition smoothed by cooperating health officials on both sides of the ocean. But in this classic story, pride and prejudice intervened. The lawyers came next.

Now in New York there is a small boy, already bruised, who will learn again that he carries no immunity from pain in the world of international diplomacy.