Your last step is wrong.
$$\frac{1}{\sigma^2}\sum_{i=1}^n (y_i-ax_i)x_i = 0 \\ \sum_{i=1}^n (y_i-ax_i)x_i = 0 \\ \sum_{i=1}^nx_iy_i-\sum_i^nax_i^2=0\\a=\frac{\sum_{i=1}^nx_iy_i}{\sum_{i=1}^nx_i^2}$$$$\frac{1}{\sigma^2}\sum_{i=1}^n (y_i-ax_i)x_i = 0 \\ \sum_{i=1}^n (y_i-ax_i)x_i = 0 \\ \sum_{i=1}^nx_iy_i-\sum_{i=1}^nax_i^2=0\\a=\frac{\sum_{i=1}^nx_iy_i}{\sum_{i=1}^nx_i^2}$$
This should match all other solution suppose you have no intercept (centered all your values)