The Briton, seeded third, won 6-2 4-6 6-4 6-1 to set up a match with Australia's Nick Kyrgios.
Murray began and ended the contest in fine form, but showed his frustration as Portugal's Sousa fought back in the second and third sets.
Fellow British number one Heather Watson lost 6-2 6-4 to American Sloane Stephens on Court Seven.