A 27-year-old undercover policeman who was conducting a narcotics investigation in far Southwest Washington was shot in the head at close range and critically wounded yesterday, D.C. police officials reported.

The wounded officer was identified as Bruce W. Wilson, a member of the force for five years. Wilson, attached to the vice unit in the Seventh District, was shot about 3:25 p.m. in the rear of the 200 block of Elmira Street SW.

Officials at Greater Southeast Community Hospital, where Wilson underwnet surgery last night, said his vital signs were unstable and his prognosis was "not good."

Meanwhile, homicide detectives were reported questioning two youths who had been stopped just after the shooting by an off-duty policeman who lives nearby.

After the shooting, dozens of policemen swarmed into the area, about a half mile from the Prince George's County line. A police helipcopter hovered overhead. An intense search continued last night for the weapon used in the attack and for anyone involved in the incident.

According to accounts provided by fellow officers in the Seventh District, Wilson and his partner, Peter L. Presly returned yesterday to Elmira Street to resume an investigation they began in the area last week.

Shortly after the shooting took place, police said, the two undercover officers made a narcotics purchase in the 200 block of Elmira Street and took a man into custody.

Police said Presly took the man to the 4300 block of Martin Luther King Jr. Avenue, where he and Wilson had parked their white, unmarked police cruiser.

Meanwhile, Wilson remained behind to look for other persons he wanted to question in connection with the drug investigation, police said.

Presly reached the cruiser with the man he had taken into custody, police said, where he encountered an off-duty policeman who lives nearby, Presly asked the off-duty officer, who was not identified, to hold the man while he returned to Elmira Street, about 150 yards away, to check on his partner, police said.

The shooting occured before Presly returned, according to police.

According to police, the shot was heard by D.C. police Sgt. Otis Lindsay, of the Seventh District, who lives in the 200 block of Elmira Street, Sgt. Lindsay, who had just returned down work, opened the door of his apartment and saw two youths running up a staircase, police said.

When the youths saw Lindsay, police said, they began to shout that a man had been shot.

Lindsay seized the youths and was holding them when Presly entered the apartment building, police said.

It was not immediately clear last night whether Presly was searching for his partner or had already found him wounded. Lindsay and Presly held the youths until other officers arrived and removed them for questioning.

Meanhwile, another Seventh District policeman, identified as Officer Milton Costin, found Wilson lying wounded behind a trash receptacle in the rear of one of the three-story brick apartment houses on Elmira Street.

Costin administered mouth-to-mouth resuscitation until a Fire Department ambulance arrived to take the wounded officer to the hospital, police-said.

Wilson reached the hospital at 3:45 p.m. and an examination there showed powder burns to the scalp, indicating that he had been shot at close range.

During surgery that lasted from 5 p.m. to 7:25 p.m., doctors removed a blood clot from his brain, but could remove only a part of a bullet that was lodged there.

Wilson was transfered to the intensive care unit after sugery.

He is married an the father of a 2-year-old son.

The man taken into custody by Wilson and Presly before the shooting also was beign questioned last night by investigators. No link had been established between him and the shooting, officials said, and no charge had been placed against him.

It could not be immediately determined last night whether there had been witnesses to the shooting. However, some neighborhood residents said that many persons were outdoors at the time and that one or more of those persons have witnessed the incident.