Pakistan began its efforts to acquire nuclear weapons in 1972, spurred on by fears that India was developing nuclear weapons. (India detonated a "peaceful nuclear device" in 1974, and a weaponized warhead in 1998. The distinction between a "peaceful nuclear device" and an atomic bomb is about the ends to which one puts it, and thus not especially significant to a state like Pakistan.) They had several means of approaching the problem, and spent a relatively long time working on it. Their challenges included the fact that they were a fairly poor state (Prime Minister Bhutto famously said in 1965 that if India got the bomb, the Pakistani people would "eat grass" if they needed to to get one of their own), that their scientific and technical infrastructure was not especially well-developed, and that they were close allies with the United States, who did not want them to proliferate.
It took them until around 1990 (we estimate) to acquire a weapon, so it was a fairly long path (about 20 years — or ~10X longer than the Manhattan Project). Some of this work was indigenously developed (it had to be — you can't just make a bomb industry from pilfered material alone). But some of it came from abroad. The metallurgist A.Q. Khan studied in Europe in the 1960s and got a job working as a translator for the Dutch commercial uranium enrichment company URENCO. In such a role he was given access to blueprints for uranium enriching centrifuges. In the 1970s he fled Europe and brought the knowledge back to Pakistan and began working on developing the industrial infrastructure necessary to manufacture their own centrifuges.
In the 1980s, the Pakistanis received technical assistance from the Chinese, who sold them warhead designs among other things. They also attempted to purchase dual-use technology (including reactors) from Canada, France, Germany, and other states over this period. By the late 1980s, these varied approaches had given them enough fissile material for a working bomb, which they worked to weaponize by the 1990s (testing several warheads in 1998).
Part of the answer to how they did it is that by the 1970s, there was a lot of nuclear knowledge diffused throughout the world. Basic information about the early types of fission weapons had been declassified for decades, as had the workings of many different types of enrichment plants (including gas centrifuges, which were never under tight controls on account of their originating from the Soviet Union) and nuclear reactors (which had become commonplace in the world). There is still a big step between knowing how to build these things and actually building them, but with two decades of effort practically any state with scientific and technical capacity can probably pull it off, if nobody stops them. The US reliance on its Pakistani alliance during the Soviet-Afghan War and beyond complicated efforts to put pressures on them to end their nuclear work, which was at times so transparent that it was discussed in the New York Times.
There are several good books on the Pakistani program that go into far more detail than the above does. Feroz Khan's Eating Grass: The Making of the Pakistani Bomb (Stanford University Press, 2012) is probably the most complete source out there at the moment. Because this information is still highly classified within Pakistan, and much was deliberately not written down, most of what we know about their program comes out of either published propaganda by the government, or anonymous interviews with participants. It makes it a tricky thing to know about.
Just a reminder that Pakistan's first test of a nuclear weapon occurred in 1998, so discussion of the nuclear situation between Pakistan and India is off-limits here, but, as there is plenty of room to discuss the origins of the program and development pre-1996, I've approved this post. Just keep the Twenty-Year rule in mind please!