How to activate maintenance page (WP Maintenance Mode) programmatically

One of the WP Maintenance Mode users asked the support team how can the maintenance page be activated/deactivated programmatically. In case you were wondering the same thing, this is the solution: