The Serman and Panzers started out with 75 mm cannons. The Germans fired a high-velocity shell because their barrels were longer.
Slower rounds from the Sherman bounced off the Panzers.
I believe the designers for the Sherman made the barrel shorter because the tank had to be shipped overseas and they didn’t want the barrel to stick out beyond the front of the vehicle. This made the gun useless and many Allied tankers died for the sake of convenience.
The shorter barrel reflected doctrine at the time that in combat when traversing obstacles like ditches, ramming a long barrel into the ground was a bad thing.
Contrary to popular belief, the glaxis of the Sherman was quite effective at defeating German 75mm and 88mm rounds when fired head-on from a distance. At less than head-on angles, the Sherman's glaxis became invulnerable to the 88 at any distance.
Furthermore, when encountering the rare German heavies on the battlfield, Shermans were generally ordered to bypass them and call up tank destroyer units deal with them.