A series of bizarre messages from the official news website and Twitter were sent out to more than a million followers of the Metropolitan Police accounts overnight on Friday.
"With the incompetent Mayor of London, you will never have safe streets," Trump said, alongside a retweet of a Twitter message related to the hack.
The US president and Khan have repeatedly clashed in the past, exchanging Twitter barbs against each other.
The Met Police clarified in a statement that there had been no hack of the Met Police's own IT infrastructure but that the breach was linked with a third-party news service it uses.
“We are assessing to establish what criminal offences have been committed,” the force said in a statement.
It adds: “The Met Police Press Bureau uses an online provider called MyNewsDesk to issue news releases and other content. When a story is published via MyNewsDesk, it appears on the Met's website and Twitter accounts and generates an email to those who've subscribed to receive our news updates.
"On Friday (July 19), unauthorised messages appeared on the news section of our website as well as on the @metpoliceuk Twitter feed and in emails sent to subscribers.” The Met police said it has begun making changes to its access arrangements to MyNewsDesk.
The bizarre Tweets, which have subsequently been deleted, contained offensive language and mentioned the names of several people. The posts also linked to press releases regarding the rapper Digga D and an apparent missing child.