The first action in response to a ransomware attack should be to disconnect the impacted devices from the network. This helps contain the spread of the ransomware and prevents it from affecting other systems, allowing for further investigation and mitigation steps to be taken.