SRY signaling cascade
The war between FOXL2 (♀) and SOX9/DMRT1 (♂)Edit
Early in the development of the embryo, the gonad has the potential to form either testis or ovary. Its fate hasn't yet been determined by "chromosomal sex." Two separate gene regulatory networks fight for control. The SOX9 gene regulatory network tries to shut down FOXL2 and cause the gonads to become the Leydig and Sertoli cells of the testes. The FOXL2 tries to shut down SOX9 and causes the gonads to become the follicular cells of the ovaries.
For the gonads to keep their programming as testes, the SOX9 protein has to keep getting itself produced. If this feed-forward loop is broken, SOX9 slowly dwindles as the proteins are degraded and the cell's programming will be reverted. FOXL2 tries to block this feed-forward loop by getting in the way of SOX9's promoter (named TESCO.) To stay on top, SOX9 has to block the production of FOXL2 or it will lose its battle to make (and maintain) balls out of the nascent gonads. To keep FOXL2 repressed, SOX9 stimulates the production of a henchman protein, DMRT1. DMRT1 blocks the production of FOXL2 by sitting on the region of DNA promoting its transcription. SOX9 makes more SOX9, and SOX9 makes DMRT1 which blocks FOXL2 which wants to block SOX9, keeping it dominant while keeping FOXL2, and the gonad's hopes and dreams of becoming a uterus, dormant.
So we see that each cell in the gonads has a sort of toggle switch: either SOX9 keeps producing itself and toggles the switch to "balls", or FOXL2 keeps producing itself and switches the cell to "ovaries." But this just explains how the switch stays flipped... how do we tell which network wins early on, and thus what the switch is flipped to?
The Y chromosome tilts the scalesEdit
The Y chromosome actually has only one gene, SRY, that matters to us and it's active for a very short window of time (~3 days) before it's switched off permanently. All that SRY seems to do is bind to SOX9's promoter region, TESCO, and thus get a bunch of SOX9 produced in the early days of the embryo. Once enough SOX9 is active, it keeps itself alive by binding to TESCO itself, and actually switches off SRY! So the Y chromosome is more of a starter pistol than a continuing player in the fate of the gonads.
Fish are really interesting, because many change gender (most FTM, but a few MTF!) In these, environmental or endocrinological events flip the toggle switch, either activating SOX9 and spinning down FOXL2. This demonstrates it may be possible to flip the switch ourselves.. Genetic Sex Differentiation in Fish is a hell of a page turner. Many species of fish also use a Z/W chromosome system instead of (or even in addition to) X/Y, but they still have a gene network very similar to SRY.