The team at Blocknative wrote an excellent post detailing Canceled Transactions that answers your question:
Here is what they say about Canceled TX:
What are Canceled transactions?
On Ethereum, a Cancel transaction is an attempt to overwrite a currently pending transaction with a new transaction. It's important to note that Canceled transactions are a convention and not a standard. Typically, a Cancel transaction will have:
- An identical nonce,
- From the same Wallet address,
- Sent to an external account (not a smart contract), with
- At least a 10% higher gas fee,
- but Zero value, and
- Gets signed-and-successfully-submitted before the original transaction is confirmed.
The core of the idea is that, since miners are incentivized to prioritize transactions with more gas, the cancel transaction should be confirmed before the original transaction – even though it entered the mempool later. In other words, Cancel transactions are kind of like probabilistic mulligans.
So yes, you can submit a Cancel TX to the network to try and invalidate a pending TX. But nothing is guaranteed. Once you submit a Cancel you must hope that it is mined before your original transaction.