Recently, the widespread deployment of the Internet of Things (IoT) applications has contributed to the development of smart cities, which utilise smart applications to maximize operational efficiency, and thereby the quality of services and the wellbeing of people. In this paper, we propose an attack and anomaly detection technique based on machine learning algorithms to mitigate IoT cybersecurity threats in a smart city. Notably, while there are many different machine learning (ML) algorithms, including computationally expensive deep learning network, we opted for using artificial neural network (ANN) since an ANN can provide a simple and computationally faster architecture as needed for smart city operations. A widely used performance metrics, namely, accuracy, precision, recall, and F1 score are utilized to evaluate the model. Experiment results with the recent attack dataset demonstrate that the proposed technique can effectively identify the cyber attacks and outperform results reported in an existing work