It's entirely possible, and it works very well.
The most popular public-key cipher, RSA, has a simple basis, although the implementations and the math behind them are a lot more complex. In RSA, you just take a block of plaintext, and treat it as one gigantic, really huge number. Then you raise it to an extremely high power (one with hundreds of digits), divide it by a still bigger number (the modulus), and then take the remainder as the ciphertext. The exponent used is the encryption key. To decrypt, you just repeat the operation, but with a different exponent that represents the decryption key. As long as the modulus, encryption exponent, and decryption exponent have a certain mathematical relationship to each other, it works perfectly. Anything that is encrypted with one of the keys can be decrypted (only) by the other key.
Breaking RSA requires factoring numbers with hundreds or thousands of digits, or taking discrete logarithms of similar numbers. Right now, nobody knows how to do that with any efficiency, so RSA is considered secure with a sufficient key length (several thousand bits).
There are many other public-key algorithms. The principles have been known for about fifty years, although they didn't become known outside of secret government circles until the 1990s or thereabouts.