A UK citizen opening a foreign company

Let’s say you wanted to open a company in a foreign country like Chile for example and let’s say the corporation tax rate happens to be lower than in the UK (19% in the case of an LLC).

Is this perfectly legal and ok to do? How is this treated when it comes to tax treatment? You pay the foreign corp tax and then pay the difference to the UK?