Birds have sex to produce young just like other species of animals. However, they are equipped a little differently than many – male parrots do not have penises. Their reproductive organs are contained internally and they have an opening in their vent area like the female. In order to transfer ejaculate to the female, the male climbs on top of her back and the openings are pressed together.
It is very possible that you have witnessed your bird masturbating. It is most evident in male birds. My cockatiels will squat on their perches and switch their tails back and forth until they are satisfied. When a male is on top of the female you will see similar behavior but also a lot of wing flapping. This makes it seem like an aggressive act, but the wings are in motion mostly to keep the male from falling off.
Once the sex act is complete, the sperm travels up the oviduct tube to the ova where fertilization occurs. The fertilized ovum is joined to a yolk sac and the two travel back down the oviduct to an area where the shell is formed around them and then expelled through the chloacal opening.