Query this REST API with any email address and it will extract and return the top level domain (TLD) against Mozilla TLDs official listing. It supports a range of scenarios with domains and subdomains, including .edu, .co.uk, and others. It also supports parsing unknown tlds.
The code is based on the tld-extract library, which in turn is a port of a yks/PHP library. The docs are simple: the API accepts only 1 query parameter - emailaddress - and returns JSON with the extracted TLD, and the email queried back.
For example: https://email@example.com, will return the following: