Compelling features such as low power consumption and low complexity make LoRaWAN one of the most promising technologies to provide long-range connectivity to resource-constrained devices. However, LoRaWAN suffers from limited scalability since it uses an Aloha-based protocol for accessing the channel that causes a huge amount of frame collisions when the number of devices (or the network load) is high. This paper presents LFS-CSMA, a new medium access control mechanism that enhances the scalability of LoRaWAN networks by just combining the well-known slotted Aloha and CSMA schemes in a novel manner. With LFS-CSMA, longer frames are transmitted earlier within a given timeslot. Thus, devices with short frames to be transmitted can check the channel availability before sending them and avoid collisions if they detect an ongoing transmission. Performance results show that LFS-CSMA causes far less collisions than traditional MAC mechanisms, thus improving the scalability of LoRaWAN networks significantly.