The presence of a distinct nucleus, the compartment for confining the genome, transcription and RNA maturation, is a central (and eponymous) feature that distinguishes eukaryotes from prokaryotes. Structural integrity of the nucleus is maintained by the nuclear envelope (NE). A crucial element of this structure is the nuclear pore complex (NPC), a macromolecular machine with over 90 protein components, which mediates nucleo-cytoplasmic communication. We investigated the provenance of the conserved domains found in these perinuclear proteins and reconstructed a parsimonious scenario for NE and NPC evolution by means of comparative-genomic analysis of their components from the available sequences of 28 sequenced eukaryotic genomes. We show that the NE and NPC proteins were tinkered together from diverse domains, which evolved from prokaryotic precursors at different points in eukaryotic evolution, divergence from pre-existing eukaryotic paralogs performing other functions, and de novo. It is shown that several central components of the NPC, in particular, the RanGDP import factor NTF2, the HEH domain of Src1p-Man1, and, probably, also the key domains of karyopherins and nucleoporins, the HEAT/ARM and WD40 repeats, have a bacterial, most likely, endosymbiotic origin. The specialized immunoglobulin (Ig) domain in the globular tail of the animal lamins, and the Ig domains in the nuclear membrane protein GP210 are shown to be related to distinct prokaryotic families of Ig domains. This suggests that independent, late horizontal gene transfer events from bacterial sources might have contributed to the evolution of perinuclear proteins in some of the major eukaryotic lineages. Snurportin 1, one of the highly conserved karyopherins, contains a cap-binding domain which is shown to be an inactive paralog of the guanylyl transferase domain of the mRNA-capping enzyme, exemplifying recruitment of paralogs of pre-exsiting proteins for perinuclear functions. It is shown that several NPC proteins containing super-structure- forming alpha-helical and beta-propeller modules are most closely related to corresponding proteins in the cytoplasmic vesicle biogenesis and coating complexes. From these observations, we infer an autogenous scenario of nuclear evolution in which the nucleus emerged in the primitive eukaryotic ancestor (the "prekaryote") as part of cell compartmentalization triggered by archaeo-bacterial symbiosis. A pivotal event in this process was the radiation of Ras-superfamily GTPases yielding Ran, the key regulator of nuclear transport. A primitive NPC with approximately 20 proteins and a Src1p-Man1-like membrane protein with a DNA-tethering HEH domain are inferred to have been integral perinuclear components in the las common ancestor of modern eukaryotes.