Nitrogen chemistry in protoplanetary disks and the freeze-out on dust particles is key to understand the formation of nitrogen bearing species in early solar system analogs. So far, ammonia has not been detected beyond the snowline in protoplanetary disks. We aim to find gas-phase ammonia in a protoplanetary disk and characterize its abundance with respect to water vapor. Using HIFI on the Herschel Space Observatory we detect, for the first time, the ground-state rotational emission of ortho-NH$_3$ in a protoplanetary disk, around TW Hya. We use detailed models of the disks physical structure and the chemistry of ammonia and water to infer the amounts of gas-phase molecules of these species. We explore two radial distributions ( confined to $<$60 au like the millimeter-sized grains) and two vertical distributions (near the midplane where water is expected to photodesorb off icy grains) to describe the (unknown) location of the molecules. These distributions capture the effects of radial drift and vertical settling of ice-covered grains. We use physical-chemical models to reproduce the fluxes with assuming that water and ammonia are co-spatial. We infer ammonia gas-phase masses of 0.7-11.0 $times$10$^{21}$ g. For water, we infer gas-phase masses of 0.2-16.0 $times$10$^{22}$ g. This corresponds to NH$_3$/H$_2$O abundance ratios of 7%-84%, assuming that water and ammonia are co-located. Only in the most compact and settled adopted configuration is the inferred NH$_3$/H$_2$O consistent with interstellar ices and solar system bodies of $sim$ 5%-10%. Volatile release in the midplane may occur via collisions between icy bodies if the available surface for subsequent freeze-out is significantly reduced, e.g., through growth of small grains into pebbles or larger.