Certain genes cause chemical reactions that result in the development of testes. Embryos are gonadally identical, regardless of genetic sex, until a certain point in development; then the testis-determining factor causes male sex organs to develop, while lack of this factor will cause the embryo to develop as physically female.
The TDF factor is encoded by the SRY gene located in the Y chromosome. It is a DNA binding protein, that enhances other transmission factors, or is a transcription factor itself. Its expression directly or indirectly causes the development of primary sex cords, which will later develop to seminiferous tubules. These cords form in the central part of the undifferentiated-yet gonad, turning it into a testis. The testis then starts secreting testosterone and the Mullerian Inhibiting Substance.
Older texts discuss the role of the HY antigen in the control of testicular development, but this was later disproven.
Conversely, such a cross-over event also can result in a Y chromosome that is missing its TDF, replaced with the corresponding sequence from the end of the X chromosome. Individuals who inherit this Y chromosome will develop as females, despite having the normal male chromosomal set of one X and one Y. However, the lack of two X-chromosomes gives complications to such females, called Turner syndrome.