Both were shot in the head, one of the sources said. Few other details were available.
They were rushed to a hospital in critical condition, said police spokesman Sgt. Lee Jones.
The families of the fallen officers were at Woodhull Medical Center on Saturday, as dozens of police officers gathered in a show of support.
The officers, one with two years' experience, the other with seven years on the job, were normally assigned to downtown Brooklyn but were working a "critical response" detail in an area with higher crime, police said.
Police were investigating posts he allegedly made on Instagram.
The shooting occurred near Myrtle and Tompkins avenues in the Bedford-Stuyvesant section of Brooklyn.
Neighborhood residents were jolted.
"This can't happen. If you mad at somebody, be mad at the person that you are mad at. Now, we have two families that (are) missing somebody for the holidays," Shaniqua Pervis said.
"Where is your humanity? I know it's a war going on and shoutout to Eric Garner's family and everybody else who lost somebody, but you're not at his house, on his lawn. This is two (officers). You don't even know if they were good or bad. I don't condone this, and I'm not with it."
The woman was referring to the controversial July death of an unarmed black man after New York police officers on Staten Island wrestled him to the ground, with one of the officers wrapping his arm around Garner's neck in a chokehold.
A grand jury's decision not to indict the police officer in the Garner case, as well as a separate grand jury's refusal to indict an officer in a controversial police shooting of unarmed teen Michael Brown in Ferguson, Missouri, led to nationwide protests against the police.
In a statement, activist the Rev. Al Sharpton said the Garner family was outraged by news of the shootings.
"Any use of the names of Eric Garner and Michael Brown, in connection with any violence or killing of police, is reprehensible and against the pursuit of justice in both cases," the statement said. "We have stressed at every rally and march that anyone engaged in any violence is an enemy to the pursuit of justice for Eric Garner and Michael Brown... The Garner family and I have always stressed that we do not believe that all police are bad, in fact we have stressed that most police are not bad."
But what the uniform represents a is painful reminder of injustice.
Last Saturday, two New York officers were assaulted on the Brooklyn Bridge during demonstrations that have been mostly peaceful. Police arrested four people.
Tensions between the community and police have heightened around the country since the Brown and Garner deaths.
"This could not have come at a worse time," City Councilman Robert Cornegy said.
So far, police have not commented on the motive for the Brooklyn shootings, except to say the officers were not engaging the shooter in any way when they were shot.
The city's police union and Mayor Bill de Blasio have sparred over the treatment of officers.
The Patrolmen's Benevolent Association recently sent a form for members to sign requesting the mayor not attend funerals of anyone killed in the line of duty, accusing de Blasio of "consistent refusal to show police officers the support and respect they deserve."
The mayor's office expressed disappointment with the PBA.
"Incendiary rhetoric like this serves only to divide the city, and New Yorkers reject these tactics," the city said in a letter. "The mayor and the speaker both know better than to think this inappropriate stunt represents the views of the majority of police officers and their families."
And in Florida......