Follow this guide.

Summary:

Download Electrum and verify the signature to prove it was not modified in transit. Create a new Standard Wallet and choose "Create a new seed". Electrum will give you a seed phrase which you should write down on paper.

If using Bitcoin-Qt, click Window -> Console.

If your wallet is encrypted, use this command to decrypt it for 5 minutes (300 seconds):

walletpassphrase your-wallet-passphrase 300

If addresses with balance are known:

Use the dumpprivkey command to get the private key. Repeat for as many bitcoin addresses as have money in them. dumpprivkey <your bitcoin address>

If addresses with balance are not known:

Use the dumpwallet command to get all private keys from the wallet. dumpwallet path/to/exported-wallet.txt

In the Electrum window, click Wallet -> Private Keys -> Sweep. Paste the private keys from Bitcoin-Qt here. Check the resulting transaction is okay and click Broadcast to sweep from the addresses in Bitcoin Core to the Electrum wallet.

If the address generated from the private key is wrong, then on the Sweep Private keys dialog box in Electrum click the Info box in the upper-right. It will give instructions for prefixing your private key so that the correct address is generated. For example if your address starts with 3 then use p2wpkh-p2sh:[your-private-key].

Warning: Make sure the Electrum wallet is not a watch-only wallet. The Electrum window title bar should not say [watching-only].