You have a hybrid deployment of on-premises Exchange Server and Exchange Online in Office 365. When you try to add and verify a domain in the Office 365 admin center, you receive the following error message after you add the TXT record or MX record:
An error occurred while working on your domain. Please go back to the Domains page to restart the process.
When you go to the Domains page, you're redirected to the Domain Setup page. However, a new TXT or MX record is generated. After you update the TXT or MX record, you receive the same error message again. You cannot verify the domain.
The domain name that you're trying to add to Office 365 is already being used in the on-premises Exchange federation trust as the primary federation organization identifier (ApplicationUri).
Note To confirm that this is the cause of the issue, open the Exchange Management Shell, and then run the Get-FederationTrust cmdlet to locate the ApplicationUri attribute. Confirm that the ApplicationUri attribute is set to the domain name that you're trying to verify in Office 365.
To resolve this issue, follow these steps:
Remove the on-premises federation trust. For more info, see the following: