A patient died of a heart attack in a hospital corridor after waiting more than two hours for emergency treatment, it has emerged.