How to crop gridded data with shapefile

I believe you are looking for a combination of raster::mask() and possibly raster::crop().

Have a look at this answer from a while back, it seems the issue is similar.

Also note that you will be better off with reading the country polygon in with sf::st_read(), as the {sf} package format is newer and IMHO more user friendly than the older {sp}.