Ethereum: how to generate a valid address from the public key?

I am using this code to generate a private key, public key and address, acording to this:

The public key is generated from the private key using the Elliptic Curve Digital Signature Algorithm. You get a public address for your account by taking the last 20 bytes of the Keccak-256 hash of the public key and adding 0x to the beginning.

const { secp256k1 } = require("ethereum-cryptography/secp256k1");
const { keccak256 } = require("ethereum-cryptography/keccak");
const { toHex } = require("ethereum-cryptography/utils");

const privateKey = secp256k1.utils.randomPrivateKey();
console.log('private key :  ', toHex(privateKey));

const publicKey = secp256k1.getPublicKey(privateKey);
console.log('public key  :', toHex(publicKey));

const address = keccak256(publicKey.slice(1)).slice(-20);
console.log('address     :', '0x' + toHex(address));

However, I get a valid private and public key pair, but not the corresponding address (compared to some online converters like this and this).