Does Managing Director outrank CEO?

No, but they are the most senior employee/operational position in the firm.

A Chief Executive Officer is a specific corporate title that is applied to a principal of a corporation, specifically the chair/head of a board, so the use of that title implies that a corporate board exists as well as stockholders, etc.

A managing director is less specific. The term 'director' can be used as a title for a company principal or owner, and can be applied to someone on the board, etc. However, that title can also be applied to someone who is strictly an employee. In larger companies, you'll see titles like 'Director of Online Marketing' and those people are frequently NOT actual principals, stockholders, or directors of the corporation - they are employees. The term 'managing director' typically refers to a top-level employee who liaises between the board OR is part of the board but also has day-to-day duties.

This term is also widely used for small/individual companies where a single person is holding all titles from the principals to the employees, and they need a title. For that purpose, it's quite accurate because that person is technically a 'director' (principal) of the company and is an employee who is managing day-to-day affairs.