Sarwar was shot in the right thigh while responding to reports of a shootout at the Cypress Hills housing development.
He and his partner followed one of the suspects into the complex, where Sarwar realized he'd been wounded.
Police Commissioner Ray Kelly said police believe the round of gunfire that wounded Sarwar was unrelated to the originally reported shootout.
Detectives found shell casings on the roof of one of the buildings of the housing development. Kelly said it's not clear whether the officer was targeted or if the shot was random.
Police were questioning two people but no arrests had been made.
Sarwar was released Friday from Jamaica Hospital.
"He's in reasonable spirits, he's conscious, he's alert and his family is with him," Kelly said.
Sarwar is originally from Bangladesh and has been on the job about 1 and ? years.
Mayor Michael Bloomberg visited the officer at the hospital Friday.
"Anytime one of our police officers is shot, it is a painful reminder that our success in fighting crime is fragile," he said.
Sarwar is the sixth officer shot this year. There were 12 struck by gunfire last year, but no fatal shootings since the 2011 death of Det. Peter Figoski killed in a botched robbery in December 2011 in the same neighborhood.
"But we cannot accept shootings as inevitable," Bloomberg said. "We must do everything we can to stop them. When a young police officer is shot while on routine patrol on the Fourth of July, there is no clearer message that we need to continue to do everything we can to keep guns off our streets."
The citizens group COP SHOT offered a $10,000 cash reward for information leading to the arrest and conviction of the suspect. Anyone with information can call (800) 267-7468.
"A public servant in our community was shot walking through these developments protecting the people that they're supposed to serve," said Brooklyn community activist Tony Herbert. "What we're saying is that that is not allowed. It is not OK to shoot at police officers in our community."