The generation of terahertz radiation by heterostructure p-i-n AlxGa1−xAs/GaAs diodes excited by femtosecond optical pulses was studied experimentally and using the Monte Carlo method. It is shown that when the reverse bias varies, the terahertz generation mechanism changes. With a positive bias on the p-i-n diode, the THz generation mechanism is due to the reflection of the photoexcited electrons from the interface. With a large internal electric field, THz generation in the p-i-n diode occurs due to the acceleration of electrons at the ballistic stage of their movement in the electric field to velocities significantly exceeding the steady state velocity (“velocity overshoot”). The subsequent sharp decrease in velocity of electrons is associated with their inter-valley transitions from the Γ-valley to the L-valley of the conduction band. At electric fields less than 22 kV/cm, the effect of electric field screening by photoexcited carriers has a significant impact on the formation of photocurrent and, accordingly, on the THz generation mechanism. As the reverse bias decreases, this effect leads to a shift in the maximum of the THz pulse toward shorter times and it begins to dominate at electric fields less than 10 kV/cm.