You absolutely can; it's what you're supposed to do if a toddler runs out in front of the car, for example. Barring malfunctioning brake lights, if you rear end a suddenly stopping vehicle, you were at fault for following at an unsafe distance.
Most legislation about this (example: https://codes.findlaw.com/ca/vehicle-code/veh-sect-22109/) says stuff like "when there is opportunity to give the signal". Screech brakes, then signal.