As the United States hunted worldwide for leaders of Al Qaeda this summer, Ramzi bin al-Shibh, a key planner of the Sept. 11 terrorist attacks, was living quietly in an apartment about 10 miles from the American Consulate here, according to Pakistani law enforcement officials.

He and his Qaeda friends spent their days logging on to the Internet via satellite telephones. At night, neighbors saw them playing cards and laughing.

The story of Mr. bin al-Shibh's final month of freedom and his chaotic arrest -- on Sept. 11 of this year, as it happens -- illustrates why it is proving so difficult to eliminate Al Qaeda.

Pakistani officials say that through support from local people, elaborate secrecy and Internet communication, Qaeda members like Mr. bin al-Shibh are trying to re-establish their network. In some ways they appear to be succeeding. Since Mr. bin al-Shibh's arrest, no senior Al Qaeda officials have been captured in Pakistan or Afghanistan.

Pakistani officials are convinced that Al Qaeda's head of operations, Khalid Shaikh Mohammed, remains in Karachi, hiding in an apartment in this maze of 14 million people, just as Mr. bin al-Shibh did. Mr. Mohammed, whom American investigators consider responsible for masterminding the attacks on the World Trade Center and the Pentagon, is one of America's most sought men.

At some point in August, Mr. bin al-Shibh and six others suspected of being Qaeda members began arriving at an apartment building in the middle-class Defense Housing Authority area of Karachi, Pakistani officials said.

Their new home was two large apartments on the top floor of an empty four-story apartment building with small shops on the ground floor. There are thousands of similar apartment buildings across Karachi.

A Pakistani militant had been instructed to rent the apartment in his own name two months earlier and wait, officials said, adding that the Pakistani had not been told who would live there.

Each suspected Qaeda member took elaborate precautions to avoid detection as he arrived at the apartment, the officials said. ''They came one by one,'' said one official. ''It took them 15 days to assemble there.''

For the next month, Mr. bin al-Shibh and his associates never left the building, officials said. The Pakistani man and the wife of one suspected Qaeda member took food and other supplies there.

Mr. bin al-Shibh and the other men spent their days using three satellite phones and five laptop computers to log on to the Internet, the officials said. A compact disc writer, a set of earphones with a microphone and more than five hundred compact discs were found in the apartment, along with a television.

The men appeared to have no shortage of money and weapons. The police found what Pakistani officials called a large amount of Pakistani currency in the apartment and a small arsenal of hand grenades, rifles and pistols.

Pakistani officials say they believe that the group was manufacturing compact discs in the apartment, possibly for recruiting purposes. They also say they believe that Mr. bin al-Shibh communicated with other members of Al Qaeda online. American law enforcement officials who, according to the Pakistanis, seized the money and the equipment found in the apartment declined to comment.

Pakistani officials say Mr. bin al-Shibh's arrest disrupted Al Qaeda's network in the city but did not eliminate it. A yearlong crackdown by the country's ruler, Gen. Pervez Musharraf, has failed to stop Pakistani militants from aiding Qaeda members.

''There are a lot of Pakistanis helping them,'' said a Pakistani law enforcement official. ''I'm sure that right now there would be Pakistanis renting apartments. If they are feeling insecure they just go to another one.''

Karachi has long been a center of militancy, but it is not the lone site of such support or of anti-American sentiment. A threatened war with Iraq and American support for Israel are stoking rising anger at the United States.

In October a coalition of Islamic religious parties vowing to eradicate corruption, establish Islamic law and remove American soldiers and law enforcement agents from Pakistan won a record 20 percent of seats in the lower house of Parliament.

An error has occurred. Please try again later.

You are already subscribed to this email.

Mr. bin al-Shibh's case shows the importance of even a modicum of local support. While officials in Washington attributed his capture to American surveillance of satellite telephone calls, Pakistani officials insist that a tip from a local source led them to Mr. bin al-Shibh. They said some people in Karachi had helped hide the senior Qaeda operative, while others had betrayed him.

The description of Mr. bin al-Shibh's activities given by Pakistani officials is similar to that of a reporter for Al Jazeera television who interviewed Mr. bin al-Shibh and Mr. Mohammed in a Karachi apartment in June.

The Jazeera reporter, Yosri Fouda, said Mr. bin al-Shibh sat on the floor surrounded by three laptop computers and five cellphones and spent much of his time quietly ''fiddling with his laptops.''

Mr. bin al-Shibh said in the interview that he and Mohamed Atta, the leader of the Sept. 11 hijackers, had used an elaborate code to remain in contact by e-mail and chat rooms while Mr. Atta attended flight school in the United States.

One of the final conversations between the two men, who were roommates in Hamburg in the late 1990's, involved Mr. Atta pretending that he was a German student in America speaking to his girlfriend Jenny in Germany in a chat room, Mr. Fouda said.

The chaotic raid that netted Mr. bin al-Shibh appears to have caught him by surprise, investigators said. The Pakistani police raided several apartments on the night of Sept. 10 and entered Mr. bin al-Shibh's building about 8 a.m. on Sept. 11.

Ten heavily armed policemen burst into one of the two adjacent apartments, surprising four groggy Arab men lying on the floor, according to two witnesses. One of the men hurled a grenade, wounding three policemen. A second Arab lunged toward a bag and was shot dead by a policeman. The bag turned out to be full of grenades and ammunition, according to two witnesses.

As the police subdued the three remaining men, Mr. bin al-Shibh and other men in the adjacent apartment fired a rifle and threw hand grenades at the police. One bullet struck a policeman in the chest.

Shocked by the resistance they were encountering, the police hustled their three prisoners and four wounded colleagues downstairs. Using a megaphone, they ordered the remaining men to surrender. Mr. bin al-Shibh and two other men refused, but they sent out one Arab man's wife and child.

For the next two hours, the police fired dozens of bullets and tear gas canisters at the apartment, but Mr. bin al-Shibh and the two other men did not emerge. Around noon, five policemen again entered the building. Witnesses said they were muttering prayers to themselves and feared for their lives.

Mr. bin al-Shibh and two others made a last stand in a windowless kitchen in the corner of the apartment, firing a rifle at policemen in the hallway. Officers shouted for them to surrender, according to two witnesses. They shouted back, ''Bastard! Bastard!'' in English. When one of the men ran out of the kitchen, the police shot him dead.

At some point the rifle the surrounded men were using jammed. They then hurled kitchen knives, forks and a pan at the officers. The police finally fired a canister of vomit-inducing tear gas into the kitchen. Ten seconds later, Mr. bin al-Shibh and another man walked out coughing, with their hands up.

''By then, we were expecting we would find Osama bin Laden,'' said one of the officers involved in the raid. ''I was very annoyed when I did not see Osama.''

While the other man quickly got down on his knees, Mr. bin al-Shibh tried to grab an officer's gun and was tackled, according to witnesses. He struggled furiously as he was bound, recited verses from the Koran and shouted at the officers: ''You're going to hell! You're going to hell!'' in Arabic, according to one witness.

Most of the policemen involved in the arrest have since moved because they fear being killed in retaliation, Pakistani officials said.

But one officer said he was proud of the arrest. ''They are letting us down, us Muslims down,'' he said, referring to Al Qaeda's use of violence.