AI coding assistants like GitHub Copilot boost developer productivity, but previous studies have shown that code generated by AI coding assistants can be energy-inefficient. This study explores whether prompt engineering can guide AI coding assistants to generate greener code that consumes less energy and emits less carbon. Initially, we experimented with prompt engineering and GitHub Copilot to optimize Java code fragments, following an iterative process where the developers assessed the code optimizations proposed by the AI coding assistant, verified the generated code was functionally equivalent, measured its performance and energy consumption, and provided follow-up prompts to further optimize the code. Through our experimentation, we devised a template for green coding prompts, an approach for optimizing code across six dimensions, and a prompting strategy that developers should follow to write greener code using AI coding assistants. Next, we applied our methodology to an enterprise application and optimized its code for sustainability, reducing its energy use and carbon emissions by ~36%. Our findings show that AI coding assistants can enable developers to deliver greener code by adopting the devised prompt engineering approach.