The 36-year-old British player led 6-5 in the first set after converting his eighth break point and served out to love.
After being broken when serving to advance, Machac battled back to take the second set and then sealed the victory in a third-set tie-break.
Late in the third set, Murray was treated for an ankle injury and became irritated due to crowd movement.
In other news, third seed Daniil Medvedev defeated top-seeded Briton Cameron Norrie 7-5 6-1 in just 81 minutes.
Murray drops the suspenseful match.
Murray and Machac, a 23-year-old player from the Czech Republic, played for three hours and 27 minutes.
Following the Briton’s victory in the first set, Machac leveled the match with a break of Murray at 6-5 in the second set, which was cut short by a brief rain delay.