A method for the ab initio crystal structure determination of organic compounds by a fit to the pair distribution function (PDF), without prior knowledge of lattice parameters and space group, has been developed. The method is called `PDF-Global-Fit' and is implemented by extension of the program FIDEL (fit with deviating lattice parameters). The structure solution is based on a global optimization approach starting from random structural models in selected space groups. No prior indexing of the powder data is needed. The new method requires only the molecular geometry and a carefully determined PDF. The generated random structures are compared with the experimental PDF and ranked by a similarity measure based on cross-correlation functions. The most promising structure candidates are fitted to the experimental PDF data using a restricted simulated annealing structure solution approach within the program TOPAS, followed by a structure refinement against the PDF to identify the correct crystal structure. With the PDF-Global-Fit it is possible to determine the local structure of crystalline and disordered organic materials, as well as to determine the local structure of unindexable powder patterns, such as nanocrystalline samples, by a fit to the PDF. The success of the method is demonstrated using barbituric acid as an example. The crystal structure of barbituric acid form IV solved and refined by the PDF-Global-Fit is in excellent agreement with the published crystal structure data.