Shortly after 1 a.m., officers were in the 300 block of Laurel Avenue conducting a traffic stop when they heard a single gunshot emanating from outside the Hayward Adult School, which is on the same block.
Officers spotted and approached a man walking from the south side of the school who suddenly turned and fired a shot at the officers before running toward the school's field, police said.
The shot missed the officers, who did not return fire as they pursued the suspect into the field, where there was a brief struggle before officers handcuffed the suspect.
Police said it is unclear whether the initial shot was intended to strike police or if it was directed somewhere else in the school, which was closed and apparently devoid of people other than the suspect.
Although police did not locate any casings, they recovered the loaded handgun that the suspect dropped as he ran into the field, police said.
The boy was booked at the Hayward Police Department on suspicion of attempted murder and is being held at the juvenile hall in San Leandro.