The detection of electron spins associated with single defects in solids is a critical operation for a range of quantum information and measurement applications under development. So far, it has been accomplished for only two defect centres in crystalline solids: phosphorus dopants in silicon, for which electrical read-out based on a single-electron transistor is used, and nitrogen-vacancy centres in diamond, for which optical read-out is used. A spin read-out fidelity of about 90 per cent has been demonstrated with both electrical read-out and optical read-out; however, the thermal limitations of the former and the poor photon collection efficiency of the latter make it difficult to achieve the higher fidelities required for quantum information applications. Here we demonstrate a hybrid approach in which optical excitation is used to change the charge state (conditional on its spin state) of an erbium defect centre in a silicon-based single-electron transistor, and this change is then detected electrically. The high spectral resolution of the optical frequency-addressing step overcomes the thermal broadening limitation of the previous electrical read-out scheme, and the charge-sensing step avoids the difficulties of efficient photon collection. This approach could lead to new architectures for quantum information processing devices and could drastically increase the range of defect centres that can be exploited. Furthermore, the efficient electrical detection of the optical excitation of single sites in silicon represents a significant step towards developing interconnects between optical-based quantum computing and silicon technologies.