"If ever you want to see a man at the edges -- I'm damned if I do and I'm damned if I don't," lamented James Palmer, the beleaguered D.C. Department of Corrections director. "I'm on a real narrow path."

Palmer is the central figure in a frenzied scramble by defense lawyers, prosecutors, judges and other corrections officials to reduce the population at the D.C. Jail to 2,050 by midnight tonight, under court order.

If the population climbs over that cap, Palmer acknowledged, "I'm in trouble." He and other city officials could be found in contempt of court.

As a result, the 4 a.m. count at the D.C. Jail has taken on a new significance for Palmer. Once a routine check to confirm that no one had escaped from the jail's 18 cell blocks, it is now a process that brings a certain trepidation.

"How many people will they lock up over the weekend ? That's what worries me," Palmer said. "We have this long holiday weekend and a lot of people can get into trouble."

The challenge on Friday was to get the jail population down to a level where it could accept new arrestees and still maintain the 2,050 level this weekend, when many new inmates will be sent to the jail but few will be released. Palmer said that, because he does not know how many new inmates will arrive, he needs a "cushion" of at least 70.

At 4 a.m. yesterday, there were 1,952 prisoners there -- well below today's ceiling.

The rush to establish that cushion was only the latest crisis in a decade-long battle to control the city's prison population that peaked this summer.

On July 15, citing "massive overcrowding," U.S. District Court Judge William B. Bryant ordered the city to send no new prisoners to the jail starting Aug. 24, unless the prison population was reduced to 1,693.

On Aug. 22 the city won a reprieve, promising to reduce the jail population by 60 persons every two weeks until Nov. 22, by sending all newly sentenced prisoners to federal facilities, speeding up paroles, releasing more inmates awaiting trial and urging judges to reduce prison sentences as well as sending some inmates to the city's halfway houses. If the population exceeds the specified levels for more than two days, a ban on admitting new inmates will go into effect automatically.

Palmer and others in the criminal justice system spent last week juggling inmates among courtrooms, the jail, Lorton Reformatory, halfway houses in the District and federal prisons, all in an effort to comply with today's deadline.

It was a complicated, and not always successful, attempt to strike a balance among goals that sometimes clashed: to reduce crowding at the jail without releasing dangerous inmates, to continue locking up persons who commit crimes, and to protect the rights of the defendants.

On Aug. 23, the corrections department began relocating the prisoners to make room for new prisoners at the jail. The moves have caused problems for nearly everyone involved.

On the first day of the transfer, a man charged in a double homicide was mistakenly moved to a halfway house and was about to walk out the door when corrections authorities realized their error and sent the man back to jail.

About 150 persons have been transferred from the jail to the halfway houses since the relocation program began, Palmer said, and eight have escaped. At least four of those have turned themselves in or were arrested, he said

The escapes prompted a call to District officials from the office of Sen. Arlen Specter (R-Pa.), chairman of the Appropriations subcommittee on the District, asking for a list of all prisoners sent to halfway houses.

"We want to make sure no recidivists are being sent out into city neighborhoods," said Phil Goldberg, a spokesman for Specter.

Palmer acknowledged the error, saying that corrections officials have redoubled their efforts. He said that only "the very cream of the crop in our jails" will be transferred to halfway houses, and that no one with more than 120 days left to serve will be moved.

At the D.C. Superior Court last week, lawyers and judges were frantic over problems caused by the transfer of all newly sentenced prisoners to federal facilities, another part of the compromise. Nearly a quarter of the 93 inmates sent this week to the federal prison at Petersburg, Va., have other pending cases, creating a scheduling and transportation nightmare.

"It's been a difficult week," said D.C. Superior Court Judge Fred B. Ugast. He said the court has set up a monitoring system to track where prisoners are being sent. "Our concern is that once prisoners are transferred it may take a while to get them back."

When a prisoner leaves the District's jurisdiction a judge must sign an order before he can be returned, a procedure that Ugast said usually takes about two weeks. The expected delays prompted one judge to suggest in a memo last week that his colleagues postpone sentencing dates if a defendant has another case.

Defense lawyers, too, have felt the burdens of the transfers. One lawyer held a well-attended impromptu session in the D.C. Superior Court building to give instructions on how to get to Petersburg and to discuss with other attorneys the effects the transfers may have on their cases. A memo circulated by the Public Defender Service referred to the "jail crisis" and warned lawyers that the new procedures may result in a number of hardships, for both client and lawyer.

"This is no joke," the PDS memo read, cautioning lawyers that it will be hard to keep track of clients and that some defendants may get lost in the system. No matter how short the sentence, the memo noted, a prisoner will be put on the bus to Petersburg.

The memo also alleged that corrections officials were ignoring some sentences, including court- ordered work releases, and were shipping these prisoners to federal facilities.

Prosecutors and judges said some of the problems of court-ordered work releases and transferring prisoners who have other pending cases may be resolved this week in meetings with U.S. Justice Department officials who have been on vacation.

"If that doesn't happen," one ranking prosecutor said, "we basically have a very serious problem."